public
Description: PLEASE CHECK http://github.com/lifo/docrails/wikis
Homepage: http://weblog.rubyonrails.org/2008/5/2/help-improve-rails-documentation-on-git-branch
Clone URL: git://github.com/lifo/docrails.git
Search Repo:
documented potential gotchas in increment and increment!
fxn (author)
Thu May 08 08:51:55 -0700 2008
commit  7bb437de3fcb35bf315fb0f00ddb1e899b79534b
tree    27f268f85bd90ba85040e82e12fbed07a622382f
parent  00395c8780a463a48e90a90e1a7659026c2b48f8
...
2242
2243
2244
2245
 
 
 
2246
2247
2248
2249
2250
2251
2252
2253
 
 
 
2254
2255
2256
...
2242
2243
2244
 
2245
2246
2247
2248
2249
2250
2251
2252
2253
 
 
2254
2255
2256
2257
2258
2259
0
@@ -2242,15 +2242,18 @@ module ActiveRecord #:nodoc:
0
         save!
0
       end
0
 
0
- # 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.
0
+ # Initializes +attribute+ to zero if +nil+ and adds the value passed as +by+ (default is 1).
0
+ # The increment is performed directly on the underlying attribute, no setter is invoked.
0
+ # Only makes sense for number-based attributes. Returns +self+.
0
       def increment(attribute, by = 1)
0
         self[attribute] ||= 0
0
         self[attribute] += by
0
         self
0
       end
0
 
0
- # Increments the +attribute+ and saves the record.
0
- # Note: Updates made with this method aren't subjected to validation checks
0
+ # Increments +attribute+ via and saves the record. This method differs from
0
+ # its non-bang version in that it passes through the attribute setter.
0
+ # Saving is not subjected to validation checks. Returns +self+.
0
       def increment!(attribute, by = 1)
0
         increment(attribute, by).update_attribute(attribute, self[attribute])
0
       end

Comments

  • fxn Thu May 08 09:00:07 -0700 2008

    I think this behaviour is not consistent, but a patch could break backwards compat. So at least we document it.