ulobby / NeoEloquent

An extension of Laravel Elqouent that supports Neo4j, a native graph database
MIT License
41 stars 17 forks source link

Using `with` generates duplicates queries #52

Open SimonThordal opened 2 years ago

SimonThordal commented 2 years ago

Currently when using with we will execute two queries the first one returning the initial model and the 2nd the initial model and its relations. Example:

Person::with('organization')->find(10) generates:

MATCH (person:Person) WHERE id(person) = 10 RETURN person

and

MATCH (person:Person), (person)-[:MEMBER_OF]->(organization:Organization) WHERE id(person) = 10 RETURN person, organization

There's no reason to execute both of these queries when we could settle for the latter.