Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 829
Gazza Avatar asked Jul 17 '12 13:07

Gazza


1 Answers

How about a named scope?

scope :not_stray, where("stray IS NULL OR stray = false")

Then use:

Dog.not_stray

like image 95
Tom L Avatar answered Sep 22 '22 17:09

Tom L