neo4jrb / activegraph

An active model wrapper for the Neo4j Graph Database for Ruby.
http://neo4jrb.io
MIT License
1.4k stars 276 forks source link

Eager loading of associations via paths #872

Open cheerfulstoic opened 9 years ago

cheerfulstoic commented 9 years ago

I would really love to see something like this:

class Category
  include Neo4j::ActiveNode

  has_many :in, :parent, model_class: :Category, type: :HAS_CATEGORY
  has_many :out, :children, model_class: :Category, type: :HAS_CATEGORY

end

root_categories = Category.roots.deeply_with_association(:children, 5) # `root` scope not defined above
root_category = root_categories[0] # Cypher query!

root_category.children # No cypher query!

root_category.children[0].children[0].children[0] # No cypher queries!

Talk amoungst yourselves

Talk amongst yourselves

klobuczek commented 8 years ago

+1 I would even go a step further: .deeply_with_association(:parent, :any) To eagerly retrieve everything of arbitrary depth (of course to be used responsibly).