neo4j-php-ogm icon indicating copy to clipboard operation
neo4j-php-ogm copied to clipboard

Proposition: make pagination for related entities

Open theUm opened this issue 8 years ago • 2 comments

Doctrine has extra lazyness for this [http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/extra-lazy-associations.html] It allows to write something like $parent->getChilds()->slice(5, 10), which will result in limiting query part responsible for relational nodes matching. Can we have something similar? Doctrine way is too complex i guess, so maybe easyer will be to add something like $parent->getChilds(5,10) wich will pass limit/offset data through reflection to NodeCollectionInitializer (NodeCollectionInitializer to BasicEntityPersister->getSimpleRelationshipCollection() to getSimpleRelationshipCollectionStatement()) (I`m not sure it will work with reflections) Or simplier and clearer way will be to add limit Annotation, like OrderBy one. This will be way more better than fetch all related nodes and filter them as array.

theUm avatar Feb 27 '17 16:02 theUm

Hi @theUm

Yes, plan is to have a auto lazy loaded Collection class that would fetch entities from the db in chunks.

For ex :

1st call to getChilds() =>

  • send a count query => returns 254
  • initialize the underlying array

then for every foreach, it will check if it has enough data and if not would call the db to check the next 10.

I already did some experimentations and it is a solution that is doable.

The next approach will be possible when I re-add the native query :

So

$em->createQuery(Parent::class)->expand('children', 10, 50);

the expand would take 1 arg mandatory and optionals, first one would be the property name of the relationship on the parent class, second one is limit, third one is skip.

expand is like the Expand when you look a query with Profile and is exactly what neo4j is doing.

I hear you, stay tuned !

ikwattro avatar Feb 28 '17 10:02 ikwattro

This is almost possible by #116 . When the slice($skip, $limit) method will be added on the lazy collection, it will be possible to paginate the relationships or relationship entities

ikwattro avatar Mar 31 '17 22:03 ikwattro