-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
I have two models in HABTM relation, both of them have an observer to log any changes.
When I run "user.hubs << hub" the observer only runs on the hub and that is also the only model on which dirty tracking registers anything as changed.
When I run "hub.users << user" the observer only runs on the user and that is also the only model on which dirty tracking registers anything as changed.
What I want is that when a relation is updated both models are marked as changed, since in the underlying documents both id arrays did in fact change. But dirty tracking registers this on only one of the documents.
To achieve what I want I have to run:
hub.user_ids << user.id
hub.save
hub.users << user
This fires the callbacks on both objects once with the correct changes in the dirty tracking.
It seems to me that this should be the default behavior. Both objects had their underlying arrays changed. Both of them should run their callbacks and both of them should track the changes to those arrays. Not just one of them.
- is duplicated by
-
MONGOID-4273 Self-referencing has_and_belongs_to_many not updated properly
- Closed
- is related to
-
MONGOID-3797 HABM relations are not saved correctly on both sides if providing just model_ids
- Closed