Hello, there is a table that has a column TINYINT(1) called status. Through mysql console I see its value as 1 (when is true) but if I do this in Rails console: Mytable.status => true give me "true" rather "1". How could I change 1 to true using some method? Or true to 1? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Aug 28, 2008, at 1:08 PM, j.francisco wrote:> Hello, there is a table that has a column TINYINT(1) called status. > Through mysql console I see its value as 1 (when is true) but if I do > this in Rails console: > > Mytable.status > => true > > give me "true" rather "1". > > How could I change 1 to true using some method? > Or true to 1?Is this behavior causing a problem? If so, then explain your problem and not simply the behavior that you see. If you look at: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/MysqlAdapter.html You''ll find one possible answer: <quote> By default, the MysqlAdapter will consider all columns of type tinyint(1) as boolean. If you wish to disable this emulation (which was the default behavior in versions 0.13.1 and earlier) you can add the following line to your environment.rb file: ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans = false </quote> You then loose all booleans because MySQL doesn''t have a true Boolean column type. http://dev.mysql.com/doc/refman/5.1/en/other-vendor-data-types.html -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
Thanks Rob, that''s enough to solve my problem. JF On Aug 28, 1:41 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Aug 28, 2008, at 1:08 PM, j.francisco wrote: > > > Hello, there is a table that has a column TINYINT(1) called status. > > Through mysql console I see its value as 1 (when is true) but if I do > > this in Rails console: > > > Mytable.status > > => true > > > give me "true" rather "1". > > > How could I change 1 to true using some method? > > Or true to 1? > > Is this behavior causing a problem? If so, then explain your problem > and not simply the behavior that you see. > > If you look at:http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/My... > > You''ll find one possible answer: > > <quote> > By default, the MysqlAdapter will consider all columns of type > tinyint(1) as boolean. If you wish to disable this emulation (which > was the default behavior in versions 0.13.1 and earlier) you can add > the following line to your environment.rb file: > ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans = false > </quote> > You then loose all booleans because MySQL doesn''t have a true Boolean > column type. > > http://dev.mysql.com/doc/refman/5.1/en/other-vendor-data-types.html > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > > smime.p7s > 3KViewDownload--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---