Hello,
i have a column in my table ‘is_inappropriate’ which is boolean,
but can be null
Here is my simplified code, and i want to keep conditions in hash
type. @reviews ||=
Review.find(
:all,
:conditions => {:is_inappropriate => false})
sql result is :
select * from reviews where reviews.is_inappropriate = False
but this is what i want :
select * from reviews where reviews.is_inappropriate IS NOT TRUE
Hello,
i have a column in my table ‘is_inappropriate’ which is boolean,
but can be null
Here is my simplified code, and i want to keep conditions in hash
type. @reviews ||=
Review.find(
:all,
:conditions => {:is_inappropriate => false})
sql result is :
select * from reviews where reviews.is_inappropriate = False
but this is what i want :
select * from reviews where reviews.is_inappropriate IS NOT TRUE
Well, I’m afraid you can’t have a hash. The hash style lets you test
equality, or a range. Those are the only options. If you want to
generate the SQL “IS NOT TRUE”, then you have to use another style.
self.find(:all, :conditions =>
[“name = :name AND is_inappropriate IS NOT TRUE”,
{:name => query}])
In other words, if you pass an array consisting of a string and a
hash, the find method will substitute values in the string (like
“:name” in this example) using the values that you’ve passed in the
hash.
Just in case you weren’t aware… the second you do ‘is_inappropriate IS
NOT
TRUE’ you lock yourself into a specific database. Some databases treat
TRUE
as true, some use T., some use 1. Yuk. Of course, that’s not usually a
problem but I thought I’d point it out.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.