diff options
author | Eugene Kenny <elkenny@gmail.com> | 2016-06-17 23:39:33 +0100 |
---|---|---|
committer | Eugene Kenny <elkenny@gmail.com> | 2016-08-15 01:14:08 +0100 |
commit | 115e31440cd48a5c6f00675f69b93eb7d4410181 (patch) | |
tree | 83b9be3389bc7e6c6c376e7ca17db8e2b46db52b /activerecord | |
parent | b6c0bc9c8a6a6dc86b315566e3ab52acc1a5377d (diff) | |
download | rails-115e31440cd48a5c6f00675f69b93eb7d4410181.tar.gz rails-115e31440cd48a5c6f00675f69b93eb7d4410181.tar.bz2 rails-115e31440cd48a5c6f00675f69b93eb7d4410181.zip |
Update increment! documentation [ci skip]
The `increment!` and `decrement!` methods were recently reimplemented to
make them safe to call from multiple connections concurrently. This
changed their behaviour in a few ways.
Previously they used `update_attribute`, which calls the attribute
setter method, runs callbacks, and touches the record. Now they behave
more like `update_column`, writing the update to the database directly
and bypassing all of those steps.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index dc4af4f390..4123671430 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -329,10 +329,10 @@ module ActiveRecord self end - # Wrapper around #increment that saves the record. This method differs from - # its non-bang version in that it passes through the attribute setter. - # Saving is not subjected to validation checks. Returns +true+ if the - # record could be saved. + # Wrapper around #increment that writes the update to the database. + # Only +attribute+ is updated; the record itself is not saved. + # This means that any other modified attributes will still be dirty. + # Validations and callbacks are skipped. Returns +self+. def increment!(attribute, by = 1) increment(attribute, by) change = public_send(attribute) - (attribute_was(attribute.to_s) || 0) @@ -348,10 +348,10 @@ module ActiveRecord increment(attribute, -by) end - # Wrapper around #decrement that saves the record. This method differs from - # its non-bang version in the sense that it passes through the attribute setter. - # Saving is not subjected to validation checks. Returns +true+ if the - # record could be saved. + # Wrapper around #decrement that writes the update to the database. + # Only +attribute+ is updated; the record itself is not saved. + # This means that any other modified attributes will still be dirty. + # Validations and callbacks are skipped. Returns +self+. def decrement!(attribute, by = 1) increment!(attribute, -by) end |