From 7bb437de3fcb35bf315fb0f00ddb1e899b79534b Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 8 May 2008 17:51:55 +0200 Subject: documented potential gotchas in increment and increment! --- activerecord/lib/active_record/base.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'activerecord') 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 -- cgit v1.2.3