57
45

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsでwhere.notを複数連結する場合

Posted at

RailsでIS NOT NULLの条件を複数利用する場合

Comment.where.not(receiver_id: nil).where.not(value: nil)

と複数連結して書いてましたが

Comment.where.not(receiver_id: nil, value: nil)

where.not利用時も上記の用にまとめられるんですね。
両方実行結果は以下のSQLが発行されます。

SELECT `comments`.* FROM `comments` WHERE (`comments`.`receiver_id` IS NOT NULL) AND (`comments`.`value` IS NOT NULL)
57
45
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
57
45

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?