Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3090

referenced n-n relation incomplete tracking

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 6.1.1
    • 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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            herregroen herregroen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: