gotagota日記

「面白きことは良きことなり」

カラムが blank のやつを抜き出した時のメモ

Rails でとあるテーブルの中の特定のカラムが空(≒blank)のものだけを抜き出したいときは、

Facility.where("phone_number <> ''")
# または
Facility.where.not(phone_number: [nil, ''])

みたいにするといいっぽい。

ちなみに、 null のものを抜き出したいときは、

Facility.arel_table[:phone_number].not_eq(nil)
# または
Facility.where("phone_number IS NOT NULL")

とする。

参考URL