我正在更新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