2008年8月21日 星期四

update_all

http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001308

  # Update all billing objects with the 3 different attributes given
Billing.update_all( "category = 'authorized', approved = 1, author = 'David'" )

# Update records that match our conditions
Billing.update_all( "author = 'David'", "title LIKE '%Rails%'" )

# Update records that match our conditions but limit it to 5 ordered by date
Billing.update_all( "author = 'David'", "title LIKE '%Rails%'",
:order => 'created_at', :limit => 5 )

沒有留言: