On Sunday, 10 January 2010 14:57:15 UTC-5, Matt Jones wrote:
On Jan 9, 6:16 pm, codeinnova <sumangur...@gmail.com> wrote:
> So i had a boolean attribute in my model which gets interpreted to
> tinyint(1) in mysql by rails migrations. Now tinyint(1) accepts a
> range in mysql and i want to change my boolean attribute to an
> attribute which can accept 3 values(0,1,2).
> I made the change to the view and when i post the form selecting the
> selecting the value '2', it still gets saved as a '0'. I checked the
> params when the post is done and the value of the form element was '0'
> even though i selected '2'(I am using a dropdown list here).
> So my question really is, how can i make rails to accept more values
> without changing the type to something other than tinyint(1)? And why
> this weirdness?As others have pointed out, MySQL doesn't have a straight "boolean"
field type, so the tinyint(1) hack is used instead.You'll either need to turn off emulate_booleans (which may break other
stuff) or just change the column type, as the MySQL adapter will
detect the current type as :boolean and the AR-generated accessors
will wind up casting values as booleans automatically...
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e52b40ef-b6c0-4bcc-9142-8ad4383a3382%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment