简单地说:
pry(main)> User.where(:id =>1).where(:id => 2).first
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
#user 2 is returned
如何让它运行:
pry(main)> User.where(:id =>1).where(:id => 2).first
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 AND "users"."id" = 2 LIMIT 1
#this way no user is returned, because I'm narrowing it down as much as possible
答案 0 :(得分:1)
在arel的帮助下,你可以这样做:
t = User.arel_table
User.where(t[:id].eq("1").and(t[:id].eq("2")))