Rails 4: find all records

后端 未结 4 1888
庸人自扰
庸人自扰 2021-01-31 14:02

Now that ActiveRecord::Relation#all is deprecated in Rails 4, how are you supposed to iterate all records?

Used to be like:

Foo.all.each do |foo|
  # w         


        
4条回答
  •  既然无缘
    2021-01-31 15:04

    yes, Foo.all.

    all is deprecated on an ActiveRecord::Relation (eg. Foo.where(true)), not on ActiveRecord::Base.

    http://api.rubyonrails.org/classes/ActiveRecord/Scoping/Named/ClassMethods.html#method-i-all

提交回复
热议问题