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

Fix inconsistent state when replacing an entire many to many relation

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.1.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      Previously there was a bug with many_to_many relationships that would improperly handing the unbinding of old relationships and not maintaining the new relationship when an entire many_to_many collection was replaced. Attempt at a coherent example below:

      person.preferences == [ pref1.existing ]

      person.preferences = [ pref2.new ]
      person.preferences == [ pref2.new ]
      pref1.people == [ person ] (wrong. it might have been right this long but a reload brought it back)
      pref2.people == [ person ]

      person.reload; pref1.reload; pref2.reload

      person.preferences == [ ] (wrong, should have pref2)
      pref1.people == [ person] (wrong, should no longer be related)
      pref2.people == [ person ]

      person.save; person.reload; pref1.reload; pref2.reload

      person.preferences == [ pref2 ]
      pref1.people == [ person] (wrong, should no longer be related)
      pref2.people == [ person ]

      Believe was the gist of it, but essentially it was getting into a half state between the old and new state.

      Thanks,
      Dave

            Assignee:
            durran Durran Jordan
            Reporter:
            dave@davekrupinski.com Dave Krupinski
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: