lib/mongoid/association/referenced/syncable.rb
# Update the inverse keys for the association.
#
# @example Update the inverse keys
#   document.update_inverse_keys(association)
#
# @param [ Association ] association The document association.
#
# @return [ Object ] The updated values.
Update the inverse keys for the association.
Update the inverse keys for the association .
def update_inverse_keys(association)
          if previous_changes.has_key?(association.foreign_key)
            old, new = previous_changes[association.foreign_key]
            adds, subs = new - (old || []), (old || []) - new
            if association.autosave?
              send(association.name).in_memory.each do |doc|
                adds.delete_one(doc._id)
              end
            end
            unless adds.empty?
              association.criteria(self, adds).without_options.add_to_set(association.inverse_foreign_key => _id)
            end
            unless subs.empty?
              association.criteria(self, subs).without_options.pull(association.inverse_foreign_key => _id)
            end
          end
        end
def update_inverse_keys ( association ) if previous_changes . has_key? ( association . foreign_key ) old , new = previous_changes [ association . foreign_key ] adds , subs = new - ( old || [ ] ) , ( old || [ ] ) - new if association . autosave? send ( association . name ) . in_memory . each do | doc | adds . delete_one ( doc . _id ) end end unless adds . empty? association . criteria ( self , adds ) . without_options . add_to_set ( association . inverse_foreign_key => _id ) end unless subs . empty? association . criteria ( self , subs ) . without_options . pull ( association . inverse_foreign_key => _id ) end end end
Update the inverse keys for the association.
Update the inverse keys for the association .
# If we are autosaving we don't want a duplicate to get added - the # $addToSet would run previously and then the $push and $each from the # inverse on the autosave would cause this. We delete each id from # what's in memory in case a mix of id addition and object addition # had occurred.
The updated values.
The updated values .
 Object 
association
<not_specific>
<not_specific>
association The document association.
association The document association .
example
Update the inverse keys document.update_inverse_keys(association)
Update the inverse keys document . update_inverse_keys ( association )