-
Notifications
You must be signed in to change notification settings - Fork 274
add: additional_mapped_label_names option to ActiveNode #1414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I figure folks might have some opinions on if / how this feature is implemented. If this pull is accepted, I can update the docs to reference the new option. |
Codecov Report
@@ Coverage Diff @@
## master #1414 +/- ##
==========================================
+ Coverage 96.9% 96.93% +0.02%
==========================================
Files 205 205
Lines 12417 12501 +84
==========================================
+ Hits 12033 12118 +85
+ Misses 384 383 -1
Continue to review full report at Codecov.
|
cheerfulstoic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a very small comment on this so far. For a long time I feel like there's been a shortcoming in the gem with dealing with more complex cross-cutting models and I haven't really dug into finding a good way to solve it, so I want to think about this deeper when I have the time to dedicate to it.
lib/neo4j/active_node/labels.rb
Outdated
| when String then names = [given_names] | ||
| else | ||
| fail '"additional_mapped_label_names" must be a string or array of strings' | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could do:
names = case given_names
when Array then given_names
when String then [given_names]
else
fail '"additional_mapped_label_names" must be a string or array of strings'
end|
@cheerfulstoic, updated formatting |
|
My thinking with |
|
While this PR still seems like a valuable feature to have, I think #1424 provides a better solution to my particular problem, and would largely negate my need for this. |
|
The inheritance-based label system currently in place is very understandable. It also allows for a separation of logic code, as an Admin class can inherit from User and have admin specific logic kept separate from the basic User class. I understand it's example code, but when are all users by default Authors and Admins? So I agree with Brian that some other way of implementing cross-cutting concerns should be investigated because inheritance isn't reusable. Neo4j is pretty flexible in how you choose to model the data. I'm not an authoritative source, but I find this GraphAware article to be an interesting look at the use of multiple labels.
Without more information, I can't fully understand why you are relying on so many combination of labels logically. The above article shows incredible performance hits for matching multiple labels or using negation. All that said, labels are indeed an integral part of the the Neo4j property graph model. If possible, there should be a labels property and the ability to add labels and call save to persist them. Then before a save you could apply labels based on some logic, you could also mix in a module with shared logic based on labels? |
|
Thanks @leehericks Definitely check out #1424 because we have conversation going on about some possibilities over there. I'd be curious to know what you think about the discussion / proposals |
New feature:
This pull adds an ActiveNode class method
self.additional_mapped_label_names=that maps additional labels to a model.Before this patch
The only way you can add multiple labels to a model is through inheritance or with module mixins (though I didn't actually realize the module option existed until I was writing the specs for this pull request).
After this patch
There are multiple ways a feature like this could be implemented. The way I've implemented it leaves
mapped_label_name, and the existing DSL, untouched.Each model still needs a single
mapped_label_nameand themapped_label_namerequires a constraint.additional_mapped_label_namesare in addition to themapped_label_name, and they do not require constraints.The need
In my app, I have several models that need multiple labels such as
Role::Template::Current(which has labelsRole,Current,Role::Current,Role::Template,Role::Template::Current. Currently, I need to jump through some hoops to get there...Pings:
@cheerfulstoic
@subvertallchris