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

Reassigning one-to-many association invokes dependent action improperly

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

      I've set up one-to-many association between users and ads (user has many ads, ad belongs to user) and have :autosave option set to true. When I reassign user's ads with 1 more ad it nullifies the user_id from the previous ad. Is this an intended behavior or a bug? Here is a simple test showing this case:

      ad1 = Ad.create!
      ad2 = Ad.create!
      user = User.create!(ads: [ad1])
      assert_equal [ad1], user.ads(true)
      user.ads = [ad1, ad2]
      user.save!
      assert_equal [ad1, ad2], user.ads(true) # fails, has only ad2
      

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

              Created:
              Updated:
              Resolved: