I Rails 4 kan du använda User.where.not(id: [])
vilket ger dig rätt resultat. Den producerar:
SELECT "users".* FROM "users" WHERE (1 = 1)
Tyvärr User.where('id NOT IN (?)', [])
borde vara likvärdigt men det är det inte. Det ger dig fortfarande fel resultat:
SELECT "users".* FROM "users" WHERE (id NOT IN (NULL))
Referenser:
- https://github.com/rails/rails/issues/778
- https://github.com/rails/arel/commit/cbff1bcf
- https://github.com/rails/rails/pull/8332
- https://github.com/rails/rails/commit/8d02afeaee8993bd0fde69687fdd9bf30921e805