mongoid/mongoid — Issue #1520: Reassigning one-to-many association invokes dependent action improperly
Author: semaperepelitsa
Created: 2011-12-22 15:33:35+00:00
State: open

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:

```ruby
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
```