Ruby on rails 关于ActiveRecord::Associations::CollectionProxy为什么没有save_all方法?
Ruby on rails 关于ActiveRecord::Associations::CollectionProxy为什么没有save_all方法?,ruby-on-rails,ruby,activerecord,associations,Ruby On Rails,Ruby,Activerecord,Associations,ActiveRecord::Associations::CollectionProxy类只有delete\u all和destroy\u all方法,我无法查看save\u all方法,但我使用了“build”来初始化许多对象,我想保存它们一次。有一个save\u all方法 您可以通过以下方式使用update\u all: # Update all billing objects with the 3 different attributes given Billing.update_all(
ActiveRecord::Associations::CollectionProxy
类只有delete\u all
和destroy\u all
方法,我无法查看save\u all
方法,但我使用了“build”来初始化许多对象,我想保存它们一次。有一个save\u all
方法
您可以通过以下方式使用update\u 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)