我正在尝试编写一个使用“IN”条件的 Rails 2.1 查询(我知道我应该升级,但这不是我目前的决定)。它似乎没有按预期工作。
它仅考虑基于以下查询的 Roles_id = 21,并且不会考虑 Roles_id(即 21 和 31)来显示正确的计数。
Admin.find(:all, :conditions => ["test_column1 = ? and roles_id IN (?) and test_column2 = ?",234, '21,31', 1]).count
我怎样才能做到这一点?
最佳答案
我认为你需要传递一个数组
Admin.find(:all, :conditions => ["test_column1 = ? and roles_id IN (?) and test_column2 = ?",234, [21,31], 1]).count
关于mysql - 使用 IN 和其他条件的 Rails 2.x 查询无法按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23742514/