ActiveRecord query: where a field is not true
I want to find all records where a field is not true. The working AR syntax for this is:
Dog.where(:stray => [false, nil])
Is there a less verbose way of querying for 'not true'? It really sucks having to cater for this mysql nuance everywhere.
I think you can write Dog.where(Dog.arel_table[:stray].not_eq(true)).
As a side note, I'd recommend that you set a default value for the stray column in the database, or at least require a value for it. That way you wouldn't have to make this workaround.
How about a named scope?
scope :not_stray, where("stray IS NULL OR stray = false")