Forum: Ruby on Rails How do booleans work?

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.
Mike C. (Guest)
on 2009-01-05 02:26
(Received via mailing list)
I'm a little confused as to how booleans work in Rails. Which is
better in the database? boolean or int(1)? True == 1 and False == 0,
right? Using SQLite, I tried to set a value to true inside the
database but it gave me an error. MySql didn't, so I had to switch to
int(1) for it to work. Is this just how it is?
James B. (Guest)
on 2009-01-05 03:01
Mike Chai wrote:
> I'm a little confused as to how booleans work in Rails. Which is
> better in the database? boolean or int(1)? True == 1 and False == 0,
> right? Using SQLite, I tried to set a value to true inside the
> database but it gave me an error. MySql didn't, so I had to switch to
> int(1) for it to work. Is this just how it is?

No.  True == anything other than nil or false
    False == False

DBMS have their own specific ways of handling booleans.  The DBMS
adapter handles converting that to a Ruby form.
Andrew B. (Guest)
on 2009-01-05 05:15
(Received via mailing list)
What Mike is hinting at is the way ActiveRecord abstracts database
differences. MySQL and SQLite3 probably use different column types but
this will appear transparent to the developer as ActiveRecord handles
serializing and de-serializing the column data into Ruby objects.

I am not a DBA, and I'm sure it varies from DB vendor to vendor, but I
would have to assume that the ActiveRecord Developers chose the most
appropriate column format (int(1) vs boolean) for each supported
database.

On Jan 4, 7:01 pm, James B. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.