Activerecord Enum issue

Hello! I've got a bit of an issue going on while trying to update one of my models. I have two enumerated fields in my database, i'll call them cat and dog.

So say cat has "black, white, grey" and dog has "orange, green, purple" as their enumerated values. If I try to update either of them through their active record instance as

$ar->cat = 2 

or

$ar->dog = 3
,

it works fine and is updated properly.

However, if I was to say

$ar->cat = "white" 

or

$ar->dog = "purple"
,

the cat field is set to blank, but the dog field is properly set.

In trying to figure this out, I decided to do a print_r on the activerecord instance and noticed while both fields have a dbType of enum, cat's 'type' property is integer while dog's is string.

I checked the database structure and nothing there seems to dictate this, so I assume it is somewhere within yii but I can't figure out where. There doesn't seem to be any definition of this in the model class for this table either, and though cat is set to integer, it returns the enumerated string when i try to output its value.

Does anybody have any ideas with this? If anybody needs more details on the issue I'll be happy to provide them, thanks!

Sounds like a bug maybe? However, you can manually change it by opening your model and make it a string there.

To help development if this is a bug, add an issue over here http://code.google.c…ii/issues/list, try to follow the guidelines and explain what you did.

But before you do this, depending on your experience, check your database table structure for differences between your dog and cat column.

/Martin

Thanks for the help so far! How would I go about setting the 'cat' as a string?

I tried adding this to my rules:

array('cat', 'type'=>'string'),

but it still comes out as an integer when I do a print_r on it. Is there anything else I am overlooking?

Also as far as I can tell the mysql field structures are identical besides the text values in the enum.

Okay, I got it to work! The solution was kind of strange.

In the enum that wouldn't work, 'bit' was a part of one of the enumerated words (in this case, 'Tidbit'). As soon as I took that out (changed it to 'Tidbt'), it was recognized as a string!

So, is bit some kind of reserved word in mySQL itself that is causing this, or this a yii issue?

bit is a data type field.  I often use it for flags such as a column title 'loggedIn' … i would use a bit(1) field with a value of 0 or 1.

I came across a problem a while back using a bit field.  I eventually just changed the data type to tinyint, but I'd rather figure out what is going on.  is showing up in the views for the bit field.  If I view the source in FF, that's in the source as well.  Has anyone else seen this?