lib/mongoid/associations/references_one.rb in mongoid-2.0.0.beta.15 vs lib/mongoid/associations/references_one.rb in mongoid-2.0.0.beta.16
- old
+ new
@@ -59,10 +59,18 @@
#
# Returns:
#
# A new target document.
def nested_build(attributes, options = nil)
- build(attributes) unless @target.blank? && options[:update_only]
+ options ||= {}
+ _destroy = Boolean.set(attributes.delete('_destroy'))
+ if options[:allow_destroy] && _destroy
+ @target.destroy
+ @target = nil
+ elsif @target.present? || !options[:update_only]
+ build(attributes)
+ end
+ @target
end
class << self
# Returns the macro used to create the association.
def macro