ActiveRecord boolean false returning Nil

Hi All,

I have a column type of boolean, and when the value in that column is
set to ‘false’ (eg. 0 for MySQL), it returns nil.

I have tested this in the console, and it doesn’t exhibit this
behavior there, only when running on Mongrel.

I tried wrapping the accessor call to intercept a nil and set it to
false for that attribute, but it doesn’t seem to be working. For
Example:

def needs_sound
#ActiveRecord uses method_missing to implement DB accessors, so we
call super
#to make it access the database.
res = super
if res == nil
return false
end
return res
end

The debugger says that ‘res’ is nil, but it ignores the conditional
and returns ‘res’ anyway. I have tried the conditional as a
‘res.nil?’, ‘res==nil’, ‘super == nil’.

Any help would be greatly appreciated. This is occurring for all
boolean attributes when their value is false. Thanks,

Chris

Any help would be greatly appreciated. This is occurring for all
boolean attributes when their value is false. Thanks,

That sounds like a feature. An unassigned boolean is indistinguishable
from
a false, so it’s a nil.

Well-written code never ever says ‘if bool == false’, which is probably
why
I have never seen a complaint.