= FALSE vs. 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

someone can helps me?

Jean-sébastien Jney wrote:

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

someone can helps me?

eh, maybe this?
@reviews ||=
Review.find(
:all,
:conditions => {:is_inappropriate => ‘IS NOT TRUE’})

Just use:

:conditions => “is_inappropriate IS NOT TRUE”

Chris

On Apr 17, 7:20 pm, Jean-Sébastien [email protected]

:conditions => {:is_inappropriate => ‘IS NOT TRUE’}) doesn’t work and
i’m aware that :conditions can be a string but i want to have an hash

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.

Chris

On Apr 17, 10:50 pm, Jean-Sébastien [email protected]

thanks chris, do you know if it is possible to mix hash and string
value in :conditions ?

Yeah, you can do something like this:

query = “Jean”

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.

Chris

On Apr 17, 11:35 pm, Jean-Sébastien [email protected]

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.