streetsoldier
streetsoldier

Reputation: 1319

activerecord 3.2.13 query to use where with not nil

I know there is Model.where.not for newer versions of activerecord. Is there a workaround for older version of activerecord?

I want to do something like Model.where.not(:completed_at => nil)

where completed_at is a timestamp value.

Upvotes: 0

Views: 73

Answers (1)

Ursus
Ursus

Reputation: 30071

You can use arel but it's a bit verbose

Model.where(Model.arel_table[:completed_at].not_eq(nil))

Otherwise go for the raw SQL

Model.where('completed_at IS NOT NULL')

Upvotes: 3

Related Questions