LoginSignup
104
54

More than 5 years have passed since last update.

[Rails]Where句にNOT NULLを指定する

Last updated at Posted at 2015-10-30

Googleで検索すると

User.where('name IS NOT NULL')
=> SELECT `users`.* FROM `users` WHERE (name IS NOT NULL)

みたいな書き方が出てくるけど、

User.where.not(name: nil)
=> SELECT `users`.* FROM `users` WHERE (`users`.`name` IS NOT NULL)

の方が美しいし安全です。

104
54
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
104
54