The following finder prints out IS NULL
.
User.where(:id =>nil) #=> []
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL ORDER BY created_at DESC
But I couldn't find how to print out IS NOT NULL
one?
The following finder prints out IS NULL
.
User.where(:id =>nil) #=> []
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL ORDER BY created_at DESC
But I couldn't find how to print out IS NOT NULL
one?
Try User.where("id IS NOT NULL")
This should do your job
The simplest, idiomatic ActiveRecord solution:
User.where.not(id: nil)
User.where.not(id: nil)
will work for rails 4.
User.where("id IS NOT NULL")
will work for older versions.
Rails 4
you can try this
User.where("id is not NULL")
Also if you are looking to exclude particular id and include nil values following will work
User.where("id is NULL or id != 'excluded_id'")