Class: Mongoid::Commands::Save
Class Method Summary collapse
-
.execute(doc, validate = true) ⇒ Object
Performs a save of the supplied
Document
, handling all associated callbacks and validation.
Class Method Details
.execute(doc, validate = true) ⇒ Object
Performs a save of the supplied Document
, handling all associated callbacks and validation.
Options:
doc: A Document
that is going to be persisted.
Returns: Document
if validation passes, false
if not.
13 14 15 16 17 18 19 20 21 |
# File 'lib/mongoid/commands/save.rb', line 13 def self.execute(doc, validate = true) return false if validate && !doc.valid? doc.run_callbacks :before_save parent = doc._parent doc.new_record = false parent ? Save.execute(parent) : doc.collection.save(doc.attributes) doc.run_callbacks :after_save return true end |