search
LoginSignup
44

More than 5 years have passed since last update.

posted at

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

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)

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
What you can do with signing up
44