Let's assume this domain model:
Car <--- Owns ---| Person |--- Lives ---> Location
* <--- Owns ---|1 *|--- Lives ---> 1
All the persons who own a particular car model:
select expand(in('Owns')) from Car where model = 'Volvo'
All the persons who live at a particular zip:
select expand(in('Lives')) from Location where zip = '10770'
Let's combine the above to get all the persons who own a particular car model and live at a particular zip:
select from (
select expand(in('Owns')) from Car where model = 'Volvo'
) where out('Lives') contains (zip='10770')
Minor:
- The function
expand()
transforms the result set so as you get more than just the record IDs in the print out. - Passing
Owns
/Lives
to thein
/out
functions ensures that only the edges of class typesOwns
/Lives
are traversed.