Rails will generate SQL like AND (1=0)
when you query for a column whose value is in an empty array:
Child.where(id: [])
Intuitively, you’d expect that to generate SQL like SELECT * FROM children WHERE id IN ()
, but ()
isn’t actually valid SQL. Since no rows will match that query, though, Rails works around this by generating an equivalent query that also returns no rows:
SELECT * FROM children WHERE 1=0;