-
Notifications
You must be signed in to change notification settings - Fork 5
Match
A Match-Query starts at the given ActiveOrient::Model-Class. The where-cause narrows the sample to certain records. In the simplest version this can be returned:
ORD.create_class :Industry
Industry.match where:{ name: "Communications" }
=> #<Query:0x00000004309608 @metadata={"type"=>"d", "class"=>nil, "version"=>0, "fieldTypes"=>"Industries=x"}, @attributes={"Industries"=>"#21:1", (...)}>
The attributes are the return-Values of the Match-Query. Unless otherwise noted, the pluralized Model-Classname is used as attribute in the result-set. Note that the Match statement returns a »Query«-record. Its up to the usere, to transform the attributes to Model-Objects. This is done by the »to_orient« directive, ie. »xx.Industries.to_orient «
Industry.match where name: "Communications"
## is equal to
Industry.match( where: { name: 'Communications' }).first.Industries
The Match-Query uses this result-set as start for subsequent queries on connected records. If a linear graph: Industry <- Category <- Subcategory <- Stock is build, Subcategories can accessed starting at Industry defining
var = Industry.match( where: { name: 'Communications'}) do | query |
query.connect :in, count: 2, as: 'Subcategories'
puts query.to_s # print the query prior sending it to the database
query # important: block has to return the query
end
=> MATCH {class: Industry, as: Industries} <-- {} <-- { as: Subcategories } RETURN Industries, Subcategories
The result-set has two attributes: Industries and Subcategories, pointing to the filtered datasets.
By using subsequent »connect« and »statement« method-calls even complex Match-Queries can be constructed.
Overview
Data Management
- Joining Tables, embedded Lists
- Links and Link Lists
- Relations
- Bidirectional Connections
- Working with Hashes
Public API
- Database
- Model CRUD
Misc