Module: Mongoid::Persistable::Savable
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/mongoid/persistable/savable.rb |
Overview
Defines behavior for persistence operations that save documents.
Instance Method Summary
-
#save(options = {}) ⇒ true | false
Save the document - will perform an insert if the document is new, and update if not.
-
#save!(options = {}) ⇒ true | false
Save the document - will perform an insert if the document is new, and update if not.
Instance Method Details
#save(options = {}) ⇒ true
| false
Save the document - will perform an insert if the document is new, and update if not.
# File 'lib/mongoid/persistable/savable.rb', line 25
def save( = {}) if new_record? !insert( ).new_record? else update_document( ) end end
#save!(options = {}) ⇒ true
| false
Save the document - will perform an insert if the document is new, and update if not. If a validation error occurs an error will get raised.
# File 'lib/mongoid/persistable/savable.rb', line 51
def save!( = {}) unless save( ) fail_due_to_validation! unless errors.empty? fail_due_to_callback!(:save!) end true end