Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » [SOLVED] OptionsetField not saving, please help

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 2
Go to End
Author Topic: 2462 Views
  • Harley
    Avatar
    Community Member
    153 Posts

    Re: [SOLVED] OptionsetField not saving, please help Link to this post

    That didn't seem to work I'm afriad, thinking about it though, could it be that I need to somehow convert

    $caseInfo->Contact = $data['Contact'];

    into an integer for it to be accepted by the database?

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: [SOLVED] OptionsetField not saving, please help Link to this post

    Well I'm off now, but basically that is what I was saying at the beginning... but my concern with your function is that it is getting the right DataObject and performing the update on it... as always Debug::show (or to log file) is you friend debug EVERYTHING and you'll figure it out!
    and to confirm I very much doubt DataObject get_by_id, setField or write is broken. I raised a bug on it once and was embarrassed to find I had a it all wrong... if I'd have spent a little more effort debugging...

  • apiening
    Avatar
    Community Member
    55 Posts

    Re: [SOLVED] OptionsetField not saving, please help Link to this post

    as swaiba said, it would help to see your myFifth class or just its static $db setup. Because from the screenshot i assume that you set up the contact field as boolean, that would explain why always 1 is saved to the db since both '1' and '2' casted to boolean = true. in your particiular case i would use 'Yes' => 1, 'No' => 0, or change the field type to integer

  • Harley
    Avatar
    Community Member
    153 Posts

    Re: [SOLVED] OptionsetField not saving, please help Link to this post

    Thank you both for your help.

    Apening, you are exactly right, I had figured this out and as you suspected the column in the database was cast as a boolean rather than an integer. Works perfectly now!

    2462 Views
Page: 1 2
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.