I Rails 4 kan du bruge User.where.not(id: [])
hvilket vil give dig det rigtige resultat. Det producerer:
SELECT "users".* FROM "users" WHERE (1 = 1)
Desværre User.where('id NOT IN (?)', [])
burde være ækvivalent, men det er det ikke. Det giver dig stadig det forkerte resultat:
SELECT "users".* FROM "users" WHERE (id NOT IN (NULL))
Referencer:
- 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