Forum: Ruby on Rails booleans in queries?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C7669e8b5676f61fdf202230cbcf72d8?d=identicon&s=25 mikkel (Guest)
on 2005-11-28 19:58
Hi,

Doing yet another blog engine...

In my db I have defined a boolean 'published' field...

not I want to select all published Posts...

Post.find(:all,:conditions=>"published ='t'") for sqlite

Post.find(:all,:conditions=>"published !=0") for mysql...

there has to be a better way??

Mikkel
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 technoweenie (Guest)
on 2005-11-28 20:21
(Received via mailing list)
On 11/28/05, mikkel <mikkel@helenius.dk> wrote:
> Post.find(:all,:conditions=>"published !=0") for mysql...
>
> there has to be a better way??
>
> Mikkel

Post.find :all, :conditions => ['published = ?', true]

Just as a light suggestion, try using a published_at date to achieve
this, if you have one in your model already:

Post.find :all, :condtions => 'published_at IS NULL'


--
rick
http://techno-weenie.net
C7669e8b5676f61fdf202230cbcf72d8?d=identicon&s=25 mikkel <mikkel@helenius.dk> (Guest)
on 2005-11-28 20:32
thanks a bunch!! did the trick..
This topic is locked and can not be replied to.