update_counters

update_counters(id, counters) Instance Public methods A generic âcounter updaterâ implementation, intended primarily to be used by #increment_counter and #decrement_counter, but which may also be useful on its own. It simply does a direct SQL update for the record with the given ID, altering the given hash of counters by the amount given by the corresponding value: Parameters id - The id of the object you wish to update a counter on or an Array of ids. counters - A Hash containi

reset_counters

reset_counters(id, *counters) Instance Public methods Resets one or more counter caches to their correct value using an SQL count query. This is useful when adding new counter caches, or if the counter has been corrupted or modified directly by SQL. Parameters id - The id of the object you wish to reset a counter on. counters - One or more association counters to reset Examples # For Post with id #1 records reset the comments_count Post.reset_counters(1, :comments)

increment_counter

increment_counter(counter_name, id) Instance Public methods Increment a numeric field by one, via a direct SQL update. This method is used primarily for maintaining counter_cache columns that are used to store aggregate values. For example, a DiscussionBoard may cache posts_count and comments_count to avoid running an SQL query to calculate the number of posts and comments there are, each time it is displayed. Parameters counter_name - The name of the field that should be incremen

decrement_counter

decrement_counter(counter_name, id) Instance Public methods Decrement a numeric field by one, via a direct SQL update. This works the same as #increment_counter but reduces the column value by 1 instead of increasing it. Parameters counter_name - The name of the field that should be decremented. id - The id of the object that should be decremented or an Array of ids. Examples # Decrement the post_count column for the record with an id of 5 DiscussionBoard.decrement_counter(:p

slice

slice(*methods) Instance Public methods Returns a hash of the given methods with their names as keys and returned values as values.

readonly?

readonly?() Instance Public methods Returns true if the record is read only. Records loaded through joins with piggy-back attributes will be marked as read only since they cannot be saved.

readonly!

readonly!() Instance Public methods Marks this record as read only.

inspect

inspect() Instance Public methods Returns the contents of the record as a nicely formatted string.

init_with

init_with(coder) Instance Public methods Initialize an empty model object from coder. coder must contain the attributes necessary for initializing an empty model object. For example: class Post < ActiveRecord::Base end post = Post.allocate post.init_with('attributes' => { 'title' => 'hello world' }) post.title # => 'hello world'

hash

hash() Instance Public methods Delegates to id in order to allow two records of the same type and id to work with something like: [ Person.find(1), Person.find(2), Person.find(3) ] & [ Person.find(1), Person.find(4) ] # => [ Person.find(1) ]