Reputation: 27664
There is a record with foo=nil
and bar=43
. Why does the following query does not match that record. Should it not just check only foo
since it matches with the given value (i.e nil
)?
myrecords.where("foo = ? OR bar = ?", nil, 42).first
Upvotes: 1
Views: 82
Reputation: 1940
Hey you can try this way null value is not compare in mysql for more info of NULL
values refer
Working with NULL Values
myrecords.where("foo is null OR bar = ?", 42).first
If in case you are not aware of value of object is
null
ornot null
used NULL-safe equal to operator of mysql as:
myrecords.where("foo <=> ? OR bar = ?", nil, 42).first
Upvotes: 2
Reputation: 2872
This should work:
myrecords.where("foo = ? OR bar = ?", NULL, 42).first
Upvotes: -1