lib/mongoid/relations/referenced/many_to_many.rb in mongoid-2.1.2 vs lib/mongoid/relations/referenced/many_to_many.rb in mongoid-2.1.3
- old
+ new
@@ -169,17 +169,22 @@
# @example Nullify the relation.
# person.preferences.nullify
#
# @since 2.0.0.rc.1
def nullify
- # @todo: Durran: This is wrong.
- criteria.update(metadata.inverse_foreign_key => [])
- # We need to update the inverse as well.
+ criteria.pull(metadata.inverse_foreign_key, base.id)
+ unless base.destroyed?
+ base.set(
+ metadata.foreign_key,
+ base.send(metadata.foreign_key).clear
+ )
+ end
target.clear do |doc|
unbind_one(doc)
end
end
alias :nullify_all :nullify
+ alias :clear :nullify
private
# Appends the document to the target array, updating the index on the
# document at the same time.