ActiveRecord::Associations::CollectionProxy
课程只有delete_all
和destroy_all
方法,我无法查看save_all
方法,但我使用" build"要初始化许多对象,我想保存一次。
答案 0 :(得分:1)
有update_all
但没有save_all
。
您可以这样使用update_all
:
# 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 )
如果您使用build
初始化了许多对象,那么您可以像这样保存它们(如果它们都在数组中):
initialized_objects.each(&:save)