diff options
author | Xavier Noria <fxn@hashref.com> | 2008-05-08 17:51:55 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2008-05-08 17:51:55 +0200 |
commit | 7bb437de3fcb35bf315fb0f00ddb1e899b79534b (patch) | |
tree | 27f268f85bd90ba85040e82e12fbed07a622382f /activerecord | |
parent | 00395c8780a463a48e90a90e1a7659026c2b48f8 (diff) | |
download | rails-7bb437de3fcb35bf315fb0f00ddb1e899b79534b.tar.gz rails-7bb437de3fcb35bf315fb0f00ddb1e899b79534b.tar.bz2 rails-7bb437de3fcb35bf315fb0f00ddb1e899b79534b.zip |
documented potential gotchas in increment and increment!
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 755d353031..4b43b52d5f 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2242,15 +2242,18 @@ module ActiveRecord #:nodoc: save! end - # Initializes the +attribute+ to zero if nil and adds the value passed as +by+ (default is one). Only makes sense for number-based attributes. Returns self. + # Initializes +attribute+ to zero if +nil+ and adds the value passed as +by+ (default is 1). + # The increment is performed directly on the underlying attribute, no setter is invoked. + # Only makes sense for number-based attributes. Returns +self+. def increment(attribute, by = 1) self[attribute] ||= 0 self[attribute] += by self end - # Increments the +attribute+ and saves the record. - # Note: Updates made with this method aren't subjected to validation checks + # Increments +attribute+ via and 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 +self+. def increment!(attribute, by = 1) increment(attribute, by).update_attribute(attribute, self[attribute]) end |