I've been playing around in the rails console trying to get things to work, and I notice that one of my queries keeps returning nil when it shouldn't. Upon looking at the generated SQL query I notice that it has AND (1=0)
appended to it each time. This is kind of annoying, and I'm not sure why it's doing this.
Note: Using the actable gem.
Steps to reproduce:
(After connecting to tables in rails console)
2.1.2 :xxxx > @parent = Parent.take
Parent Load (38.1ms) SELECT `parents`.* FROM `parents` LIMIT 1
=> #<Parent id: 37, ...>
2.1.2 :xxxx > @child = Child.where(id: @parent.actable_id)
SQL (0.7ms) SELECT `childs`.`id` AS t0_r0, `childs`.`attribute` AS t0_r1, FROM `childs`
...
LEFT OUTER JOIN `parents` ON `parents`.`actable_id` = `childs`.`id` AND `parents`.`actable_type` = 'child type' WHERE `childs`.`id` = 20 AND (1=0)
=> #<ActiveRecord::Relation []>
Why is this happening? How do I make it stop?
User.where(:id => [])
, since you can't writeSELECT * FROM users WHERE id in ()
in SQL. So I guess this is the approach is takes for queries it knows will return nothing, but it can't express in SQL.