-
Notifications
You must be signed in to change notification settings - Fork 210
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
Add support for multilevel many-to-many counters #367
base: master
Are you sure you want to change the base?
Conversation
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 this looks good—is it worth adding a note to the Readme file about this?
if value.is_a?(ActiveRecord::Associations::CollectionProxy) | ||
value.map { |v| v.try(relation_primary_key(original_relation, source: obj, was: was).try(:to_sym)) } | ||
else | ||
value.try(relation_primary_key(original_relation, source: obj, was: was).try(:to_sym)) |
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.
Can we pull this out into a helper method like
def relation_primary_key_from_model(model, original_relation, obj, was)
model.try(relation_primary_key(original_relation, source: obj, was: was).try(:to_sym)
end
Not sure if that's worth it, but it makes it clearer that the same thing is happening in both cases, just mapping in one.
@@ -0,0 +1,4 @@ | |||
class Reader < ActiveRecord::Base |
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 might be reading this wrong, but it looks like the Reader
class isn't actually required for the test scenario here, is it?
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.
Actually, the problem with this scenario cannot be solved so easily, and the implementation is too naive. In the scenario, we have a ReadersArticle
that updates the readers_count
counter. Everything works fine until we delete the associated AuthorsArticle
, which leads to the counter becoming out of sync.
Therefore, I don't see much benefit in this functionality. Unless leaving the technical possibility of specifying a multi-level path for the counter, and letting the implementation be up to a user, as it should be quite complex.
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.
Should we close this then?
No description provided.