{"issue":{"title":"Manual updates of HABTM ids fail after atomic_array_pushes","user":{"login":"fwoeck","id":39203,"url":"https://api.github.com/users/fwoeck","avatar_url":"https://secure.gravatar.com/avatar/859eb601e60429036e652733ec55c9eb?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"859eb601e60429036e652733ec55c9eb"},"created_at":"2011-12-28T13:09:00Z","milestone":null,"state":"open","updated_at":"2011-12-28T13:09:00Z","labels":[],"id":2671109,"closed_at":null,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"html_url":"https://github.com/mongoid/mongoid/issues/1530","body":"Hi guys!\r\n\r\nPlease consider the following spec against the latest master:\r\n\r\n```ruby\r\n  context \"when relational ids are changed manually\" do\r\n\r\n    let(:person) do\r\n      Person.create(:ssn => \"342-89-2439\")\r\n    end\r\n\r\n    let(:preference) do\r\n      Preference.create(:name => \"Test\")\r\n    end\r\n\r\n    it \"should contain unique id arrays\" do\r\n      person.preference_ids = [preference.id]\r\n      preference.person_ids = [person.id]\r\n\r\n      person.save\r\n      preference.save\r\n\r\n      preference.person_ids.should        == [person.id]\r\n      preference.reload.person_ids.should == [person.id]\r\n    end\r\n\r\n  end\r\n```\r\n\r\nIt fails in the last expectation because the \"person.save\"-operation persisted the person.id for \"preference\". So the preference.reload.person_ids equals actually [person.id, person.id].\r\n\r\nOf course the regular way of adding a relational object would be preference.people << person, but let's say I cannot use this for various reasons and I have to execute a .save on each relational partner.\r\n\r\nIs there a non-trivial way to make this spec work? \r\nManiulations of update_inverse_keys(meta) weren't successful.\r\n\r\nI replaced lib/mongoid/dirty.rb line 121\r\n\r\n  if pushes.any? && pulls.any?\r\nby\r\n  if (pushes.any? && pulls.any?) || name[/_ids$/]\r\n\r\nbut this is obviously hacky.\r\n\r\nThanks in advance,\r\nFrank","number":1530,"url":"https://api.github.com/repos/mongoid/mongoid/issues/1530","comments":0,"assignee":null},"action":"opened"}