Di Rails 4 Anda dapat menggunakan User.where.not(id: [])
yang akan memberi Anda hasil yang benar. Ini menghasilkan:
SELECT "users".* FROM "users" WHERE (1 = 1)
Sayangnya User.where('id NOT IN (?)', [])
harus setara tetapi tidak. Itu masih memberi Anda hasil yang salah:
SELECT "users".* FROM "users" WHERE (id NOT IN (NULL))
Referensi:
- 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