Reputation: 42420
How do I convert the following into something that works on sqlite and mysql? Note, internal
is nullable.
scope :external, where("internal is not true")
(In Rails 4, one can simply use:)
scope :external, where.not(internal: true)
Upvotes: 2
Views: 1423
Reputation: 1929
scope :external, where(internal: [false, nil])
That would be transformed in similar SQL (with table name and quetes probably):
internal IN ('f') OR internal IS NULL
internal IN (0) OR internal IS NULL
scope :external,
where(arel_table[:internal].eq(false).or(arel_table[:internal].eq(nil)))
Which would be:
internal = 'f' OR internal IS NULL
internal = 0 OR internal IS NULL
IS NULL
or IS NOT NULL
expressions.Expresions ... <> NULL
, ... = NULL
, ... IN (NULL)
are evaluated as false for everything.
So, NULL <> NULL
is false and NUL = NULL
is false.
Upvotes: 4