Class: Mongoid::Commands::Save

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/commands/save.rb

Class Method Summary collapse

Class Method Details

.execute(doc) ⇒ 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.



12
13
14
15
16
17
18
19
# File 'lib/mongoid/commands/save.rb', line 12

def self.execute(doc)
  return false unless doc.valid?
  doc.run_callbacks :before_save
  parent = doc.parent
  parent ? Save.execute(parent) : doc.collection.save(doc.attributes)
  doc.run_callbacks :after_save
  return doc
end