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? --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Byrne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---