Rails: Find Column Null, not Null or Empty

2018-02-04 ·

Let's find records where column is NULL or empty using Active Record

Article.where(topic: [nil, ""])

Let's now find records where column is NOT NULL or empty using Active Record

Article.where.not(topic: [nil, ""])

This Active Record expression will be converted to the following SQL query.

SELECT "articles.*"
FROM "articles"
WHERE
NOT (("articles"."topic" = '' OR "articles"."topic" IS NULL))
Copyright © 2018 All rights reserved.
Powered by Kulfon.