Jump to:

23552 Posts in 19349 Topics by 2891 members

General Questions

SilverStripe Forums » General Questions » Enum and numbers

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

Page: 1
Go to End
Author Topic: 1121 Views
  • Tuckie
    Avatar
    Community Member
    10 Posts

    Enum and numbers Link to this post

    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.

  • martimiz
    Avatar
    Forum Moderator
    1091 Posts

    Re: Enum and numbers Link to this post

    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?

  • johnmblack
    Avatar
    Community Member
    61 Posts

    Re: Enum and numbers Link to this post

    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.

  • martimiz
    Avatar
    Forum Moderator
    1091 Posts

    Re: Enum and numbers Link to this post

    @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?

  • socks
    Avatar
    Community Member
    190 Posts

    Re: Enum and numbers Link to this post

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

    1121 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.