User.create([{ :first_name => 'Jamie' }, { :first_name => 'Jeremy' }]) do |u|
u.is_admin = false
end
people = { 1 => { "first_name" => "David" }, 2 => { "first_name" => "Jeremy" } }
Person.update(people.keys, people.values)
For the Post with id of 5, decrement the comment_count by 1, and
increment the action_count by 1
Post.update_counters 5, :comment_count => -1, :action_count => 1
Executes the following SQL:
UPDATE posts
SET comment_count = comment_count - 1,
action_count = action_count + 1
WHERE id = 5
:set_sequence_name 指定自增序列
columns_hash
StatisticsLog.columns_hash.keys #=> ["independent_visitor", "created_at", "updated_at", "new_independent_visitor", "hour", "domain", "date", "id", "pv", "ip"]
StatisticsLog.column_names #=> ["independent_visitor", "created_at", "updated_at", "new_independent_visitor", "hour", "domain", "date", "id", "pv", "ip"]
StatisticsLog.name.underscore => "statistics_log"
"drugs".singularize # "drug"
StatisticsLog.human_attribute_name("pv")
=> "Pv"
For example, an Active Record User with the <tt>name</tt> attribute has a <tt>name?</tt> method that you can call
to determine whether the user has a name:
user = User.new(:name => "David")
user.name? # => true
anonymous = User.new(:name => "")
anonymous.name? # => false
Accessing attributes before they have been typecasted
benchmark 方法
merge_conditions