Reputation: 13906
Simply put:
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
How can I make it run:
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
Upvotes: 1
Views: 942
Reputation: 14944
With the help of arel you can do this:
t = User.arel_table
User.where(t[:id].eq("1").and(t[:id].eq("2")))
Upvotes: 1