Module: Mongoid::Copyable
Overview
This module contains the behaviour of Mongoid’s clone/dup of documents.
Instance Method Summary collapse
-
#clone ⇒ Document
(also: #dup)
Clone or dup the current
Document
.
Instance Method Details
#clone ⇒ Document Also known as: dup
Clone or dup the current Document
. This will return all attributes with the exception of the document’s id and versions, and will reset all the instance variables.
This clone also includes embedded documents.
20 21 22 23 24 25 26 |
# File 'lib/mongoid/copyable.rb', line 20 def clone # @note This next line is here to address #2704, even though having an # _id and id field in the document would cause problems with Mongoid # elsewhere. attrs = clone_document.except("_id", "id") self.class.new(attrs) end |