Module: Mongoid::Persistable::Savable
- Included in:
- Mongoid::Persistable
- Defined in:
- build/mongoid-6.1/lib/mongoid/persistable/savable.rb
Overview
Defines behaviour for persistence operations that save documents.
Instance Method Summary collapse
-
#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.
21 22 23 24 25 26 27 |
# File 'build/mongoid-6.1/lib/mongoid/persistable/savable.rb', line 21 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.
43 44 45 46 47 48 49 |
# File 'build/mongoid-6.1/lib/mongoid/persistable/savable.rb', line 43 def save!( = {}) unless save() fail_due_to_validation! unless errors.empty? fail_due_to_callback!(:save!) end true end |