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
Bug in modifier and trackable relation #11
Comments
@scarliav I used your branch, and A brief test shows the following traceback:
|
If you are able to figure out the cause of it. I'd be glad to change / pull Thanks! |
About the specs my idea is to show that mongoid-history is falling on that situation :) |
Was this ever solved? I am experiencing this with version 0.3.1 and mongoid 3.0.16. |
@matekb Post a repro, ideally in a form of a test for mongoid-history and I can take a look. |
I have written a test in branch Issue11 of https://github.com/matekb/mongoid-history/ that resembles my setup and problem. Please have a look! Ohh, just saw that my commit was automatically referenced in the previous message. Nice! |
So the problem is an ambiguous relationship with
This is because the model already has a relationship with User, and adding a track_history ...
:modifier_field => :modifier,
:modifier_field_inverse_of => nil, # no inverse modifier relationship Let me know if that works. |
When between the modifier model and trackable model you have more than one relation, when you try to write in the 'modifier' mongoid is returning the wrong relation.
I found that in mongoid/relations/bindings/referenced/in.rb the bind method is making something unexpected, it is returning for the
modifier
the second relation defined between the models, no the one that is created by mongoid-history in https://github.com/sarcilav/mongoid-history/blob/fixing-bug-when-trackable-modifier-has-more-than-one-relation/lib/mongoid/history/trackable.rb#L36 , I think that the problem is in the modifier you don't have to specify the relation, and it creates a weak relation.I re-wrote two models in the integration test of mongoid-history to double check that the problem is on mongoid-history https://github.com/sarcilav/mongoid-history/blob/fixing-bug-when-trackable-modifier-has-more-than-one-relation/spec/integration/integration_spec.rb
The text was updated successfully, but these errors were encountered: