activegraph
activegraph copied to clipboard
feature: has_many & has_one model_labels: [] option (instead of model_class)
Problem
Currently, when defining a has_many
or has_one
association, you indicate what the association's targets are using model_class
. This can be limiting. For example, given the models below, I want the person's has_many
association to target current signup questions AKA nodes with (:`Question::Signup`:`Current`)
labels. This could be accomplished by creating a class specifically for this purpose (i.e. Current = Class.new(Question::Signup){mapped_label_name = "Current"}
) but the class would only exist to work around neo4jrb's limitations.
class Person
has_many :out, :signups, type: :SIGNUP, model_class: ???
end
class Question
self.mapped_label_name = "Question"
class Signup < Question
self.mapped_label_name = "Question::Signup"
class List < Signup
self.mapped_label_name = "Question::Signup::List"
class Current < List
self.mapped_label_name = "Current"
end
class Destroyed < List
self.mapped_label_name = "Destroyed"
end
end
class Shift < Signup
self.mapped_label_name = "Question::Signup::Shift"
class Current < Shift
self.mapped_label_name = "Current"
end
class Destroyed < Shift
self.mapped_label_name = "Destroyed"
end
end
end
end
Proposal
Would you accept a pull request to add a model_labels
option to has_many()
and has_one()
? This option could be used instead of model_class
(an ArgumentError
would be raised if they both were included) and would indicate the labels to match against. To use the option, you would include an array of strings where each string was formatted like the label part of a cypher query.
has_many :out, :children, type: nil, model_labels: [":Current:`Question::Signup`", ":Person:Current"]