{"issue":{"created_at":"2011-11-18T07:28:31Z","state":"open","updated_at":"2011-11-23T09:04:49Z","user":{"gravatar_id":"ac5e23ccf5c7a9f58ad75ab78bf9cf26","id":124641,"url":"https://api.github.com/users/chrisberkhout","login":"chrisberkhout","avatar_url":"https://secure.gravatar.com/avatar/ac5e23ccf5c7a9f58ad75ab78bf9cf26?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"comments":11,"body":"In my application, Document objects can have many Source objects.\r\n\r\nWhen a document is updated, I need a callback to update related sources (those the document has after the update, but also any it had before the update). I can't know the pre-update sources if I do:\r\n\r\n    document.sources = []\r\n\r\nIt will only work if I do:\r\n\r\n    document.source_ids = []\r\n\r\nHere's a more detailed example:\r\n\r\n    ##[ given models ]##############################################################\r\n\r\n    class Document\r\n      include Mongoid::Document\r\n      has_and_belongs_to_many :sources\r\n    end\r\n    class Source\r\n      include Mongoid::Document\r\n      has_and_belongs_to_many :documents\r\n    end\r\n\r\n    ##[ modifying by the relation ids => OKAY ]#####################################\r\n\r\n    document = Document.create(sources: [Source.new])\r\n\r\n    document.source_ids                     # => [BSON::ObjectId('4e409eba16e17727520000b6')]\r\n\r\n    document.source_ids = []\r\n    document.save\r\n\r\n      # in before_save, before_update, after_update, after_save\r\n      document.source_ids                     # => []\r\n      document.source_ids_was                 # => [BSON::ObjectId('4e409eba16e17727520000b6')]\r\n\r\n    document.source_ids                     # => []\r\n    document.source_ids_was                 # => []\r\n    document.previous_changes[:source_ids]  # => [[BSON::ObjectId('4e409eba16e17727520000b6')], []] \r\n    document.sources                        # => [#<Source _id: 4e409eba16e17727520000b6, document_ids: [BSON::ObjectId('4e409e7d16e177275200001c')]>]\r\n\r\n    document.reload         \r\n\r\n    document.source_ids                     # => []\r\n    document.source_ids_was                 # => []\r\n    document.previous_changes[:source_ids]  # => [[BSON::ObjectId('4e409eba16e17727520000b6')], []] \r\n    document.sources                        # => []\r\n\r\n    ##[ modifying by the relation collection => PROBLEM ]###########################\r\n\r\n    document = Document.create(sources: [Source.new])\r\n\r\n    document.source_ids                     # => [BSON::ObjectId('4e409eba16e17727520000b6')]\r\n\r\n    document.sources = []\r\n    document.save\r\n\r\n      # in before_save, before_update, after_update, after_save\r\n      document.source_ids                     # => []\r\n      document.source_ids_was                 # => []\r\n\r\n    document.source_ids                     # => []\r\n    document.source_ids_was                 # => []\r\n    document.previous_changes[:source_ids]  # => [] \r\n    document.sources                        # => []\r\n\r\n    document.reload         \r\n\r\n    document.source_ids                     # => []\r\n    document.source_ids_was                 # => []\r\n    document.previous_changes[:source_ids]  # => []\r\n    document.sources                        # => []\r\n","assignee":null,"id":2277583,"number":1435,"labels":[],"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"title":"Change information unavailable when modifying relation collections","closed_at":null,"html_url":"https://github.com/mongoid/mongoid/issues/1435","milestone":null,"url":"https://api.github.com/repos/mongoid/mongoid/issues/1435"},"action":"reopened"}