我在模块中有一个Rails类
module Test
class A < ActiveRecord::Base
end
end
我遇到了查询模型的某些问题
以下查询工作正常,符合与数据库的模型连接是完美的
Test::A.all.size
Test::A.first
Test::A.find(1)
然而,当我做ActiveRecord时发现我收到错误
Test::A.find(:first, :conditions => {:id => 1})
ActiveRecord::RecordNotFound: Couldn't find all Test::As with 'id': (first, {:conditions=>{:id=>1}}) (found 0 results, but was looking for 2)
似乎有什么问题?这是查询模块内部类的错误方法吗?
答案 0 :(得分:2)
此Activerecord查询格式不可用,不久前已弃用并删除,您可以运行查询
Test::A.find(1)
或
Test::A.where(:id => 1).first
或
Test::A.find_by(:id => 1)