我正在更新rails項目的活動記錄查詢。當查詢是
foo.find(:all, :stuff, :id, :thing, @bar)
將Activerecord查詢更新爲rails 3.2格式:find(:all)to all
我會知道如何處理經常我一直無法找出如何更新。 find(:all)
或.find(:all, :conditions => {}
(find(:first) and find(:all) are deprecated),但還沒有找到這個
我正在更新rails項目的活動記錄查詢。當查詢是
foo.find(:all, :stuff, :id, :thing, @bar)
將Activerecord查詢更新爲rails 3.2格式:find(:all)to all
我會知道如何處理經常我一直無法找出如何更新。 find(:all)
或.find(:all, :conditions => {}
(find(:first) and find(:all) are deprecated),但還沒有找到這個
什麼如果,例如,你的模型是用戶,找到您要使用的所有用戶:
User.all
和特定的條件下,你可以使用:
您可以使用where:
Foo.where(:stuff => stuff, :thing => thing)
# or
Foo.where("stuff = ? AND thing = ?", stuff, thing)
另見Rails .where vs .find ...
要查找所有(再次作爲ActiveRecord::Relation
對象,而不是一個數組),你可以使用scoped:
Foo.scoped
不串起到什麼功能? – Btuman 2013-05-14 18:01:13
@Btuman它是與SQL注入作鬥爭(在[docs](http://guides.rubyonrails.org/active_record_querying.html#conditions)中推薦)。 – 2013-05-14 18:03:07
我想.where()是將條件=> {}轉換爲當前的格式,我錯過了什麼嗎? – Btuman 2013-05-14 18:06:10