Module: Mongoid::Persistable::Updatable
- Included in:
- Mongoid::Persistable
- Defined in:
- build/mongoid-6.1/lib/mongoid/persistable/updatable.rb
Overview
Defines behaviour for persistence operations that update existing documents.
Instance Method Summary collapse
-
#update(attributes = {}) ⇒ true, false
(also: #update_attributes)
Update the document attributes in the database.
-
#update!(attributes = {}) ⇒ true, false
(also: #update_attributes!)
Update the document attributes in the database and raise an error if validation failed.
-
#update_attribute(name, value) ⇒ true, false
Update a single attribute and persist the entire document.
Instance Method Details
#update(attributes = {}) ⇒ true, false Also known as: update_attributes
Update the document attributes in the database.
44 45 46 47 |
# File 'build/mongoid-6.1/lib/mongoid/persistable/updatable.rb', line 44 def update(attributes = {}) assign_attributes(attributes) save end |
#update!(attributes = {}) ⇒ true, false Also known as: update_attributes!
Update the document attributes in the database and raise an error if validation failed.
64 65 66 67 68 69 70 71 |
# File 'build/mongoid-6.1/lib/mongoid/persistable/updatable.rb', line 64 def update!(attributes = {}) result = update_attributes(attributes) unless result fail_due_to_validation! unless errors.empty? fail_due_to_callback!(:update_attributes!) end result end |
#update_attribute(name, value) ⇒ true, false
Update a single attribute and persist the entire document. This skips validation but fires the callbacks.
26 27 28 29 30 31 32 |
# File 'build/mongoid-6.1/lib/mongoid/persistable/updatable.rb', line 26 def update_attribute(name, value) as_writable_attribute!(name, value) do |access| normalized = name.to_s process_attribute(normalized, value) save(validate: false) end end |