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

Variable length path associations #777

Open cheerfulstoic opened 9 years ago

cheerfulstoic commented 9 years ago
cheerfulstoic commented 9 years ago

Proposed syntax:

has_many :out, :name, :type, variable: true

has_many :out, :name, :type, variable: {min: 1, max: 5}
cheerfulstoic commented 9 years ago

Could call as:

object.name.to_a # To get objects at the end
object.name.to_paths # To get the paths

object.name_path # To get path for `has_one`

The QueryProxy#to_paths could even work in general, perhaps, though we'd need to build one long path as opposed to building each step as a separate part of the MATCH

It would also be cool to find a way to turn this into a hierarchy of objects in an eager-loading fashion with just the one query

samis commented 9 years ago

Would this work so that you could start from one object and find the path to another object using an association like this one?

cheerfulstoic commented 9 years ago

Yeah, it should. Associations return QueryProxy objects (more or less, there's a branch in the works) and QueryProxy responds to the #match_to method, so you'd be able to say:

  source_object.variable_association_name.match_to(target_object).to_paths