Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Enum and numbers


Reply


5 Posts   1183 Views

Avatar
Tuckie

Community Member, 10 Posts

23 July 2011 at 1:24am

Edited: 23/07/2011 1:25am

I'm currently building a dropdown list based on the enum:
'Duration' => "Enum('1,2,3,4,5,6,7,8,9,10',5)"

It seems to be working fine on the form using:
$this->dbObject('Duration')->enumValues())

The only weird behavior, is every time I do a dev/build, it attempts to redefine the field with:
Field PromotionBanner.Duration: changed to enum('1','2','3','4','5','6','7','8','9','10') character set utf8 collate utf8_general_ci default '5' (from enum('1','2','3','4','5','6','7','8','9','10') character set utf8 collate utf8_general_ci default 5)

I've also tried:
'Duration' => "Enum('1,2,3,4,5,6,7,8,9,10','5')"
and got the same behavior.

Edit: taking out the default value completely results in:
Field PromotionBanner.Duration: changed to enum('1','2','3','4','5','6','7','8','9','10') character set utf8 collate utf8_general_ci default '1' (from enum('1','2','3','4','5','6','7','8','9','10') character set utf8 collate utf8_general_ci default 1)

every dev/build also.

It seems mysql is interpreting the default as an integer instead of a string upon assignment.

Avatar
martimiz

Forum Moderator, 1132 Posts

23 July 2011 at 4:06am

besides from it being weird that it is redefined every time to exactly the same format as it was before - is it harming your site/content at all?

I've also seen this happen with enum fields, but it didn't damage or change anything, as I recall. Probably some gltch in SilverStripe checking the enum fieldformat?

Avatar
johnmblack

Community Member, 61 Posts

31 August 2011 at 5:44am

Same thing here. Doesn't seem to harm content, but I'm OCD about code and process neatness and it's driving me crazy. :-)

But seriously, any unnecessary writes to DB structure should be avoided, as a matter of principle, so I would really like to figure this out.

Avatar
martimiz

Forum Moderator, 1132 Posts

31 August 2011 at 7:57am

@johnmblack: I got it as far as sapphire/core/model/Database.php, somewhere around line 321:

if(substr($spec, 0, 4) == "enum") { ...

That's where some special enum handling seems to be going on, checking if the field has changed before altering the table. So maybe you want to take it from there? :-)

Avatar
socks

Community Member, 191 Posts

19 November 2011 at 10:17am

I couldn't find a fix either, so I changed mine to: "one, two, three"