lib/mongoid/association/embedded/embedded_in/proxy.rb in mongoid-8.0.8 vs lib/mongoid/association/embedded/embedded_in/proxy.rb in mongoid-8.1.0
- old
+ new
@@ -28,19 +28,20 @@
# in the association.
#
# @example Substitute the new document.
# person.name.substitute(new_name)
#
- # @param [ Document ] replacement A document to replace the target.
+ # @param [ Document | Hash ] replacement A document to replace the target.
#
# @return [ Document | nil ] The association or nil.
def substitute(replacement)
unbind_one
unless replacement
_base.delete if persistable?
return nil
end
_base.new_record = true
+ replacement = Factory.build(klass, replacement) if replacement.is_a?(::Hash)
self._target = replacement
bind_one
self
end