On Jan 3, 2011, at 2:08 PM, Tony Primerano wrote:

> I feel like I'm missing something obvious here..
> 
> I have a Post object and it has a draft attribute.   It may be nil,
> true or false.  I want nil to be treated as false
> 
> Post.where(:draft => false) does not pick up the posts where draft is
> unset(nil)
> 
> This leaves me to query with
> 
> Post.where('draft is NOT true')
> 
> Is there a cleaner way to do this?  I prefer using hash conditions.
> I could set the draft boolean before_save but it seems wasteful.

Alter your database so that the default value for 'draft' is false.  Then 
update your database to set any nil values to false.

-philip

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to