find(:first) and find(:all) are deprecated

后端 未结 3 492
死守一世寂寞
死守一世寂寞 2020-12-19 06:36

I am using RubyMine with rails 3.2.12 and I am getting following deprecated warning in my IDE. Any Idea How can I solve this deprecated warning?

3条回答
  •  粉色の甜心
    2020-12-19 06:49

    Use the new ActiveRecord::Relation stuff that was added in Rails 3. Find more info here: http://guides.rubyonrails.org/active_record_querying.html

    Instead of #find, use #first, #last, #all, etc. on your model, and the methods that return a ActiveRecord::Relation, like #where.

    #User.find(:first)
    User.first
    
    #User.find(:all, :conditions => {:foo => true})
    User.where(:foo => true).all
    

提交回复
热议问题