Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Unsaved data

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1106 Views
  • dio5
    Avatar
    Community Member
    501 Posts

    Unsaved data Link to this post

    I have a class Tip that extends Page, and TipHolder.
    I have a class Author, Category and Province that all extend DataObject.

    On Tip:

    static $has_one = array(
          'Photo' => 'Image',
          'Province' => 'Province',
          'Author' => 'Author'
       );
    static $many_many = array(
          'Categories' => 'Category',
       );

    On Province and Author:

    static $has_many = array(
          'Tips' => 'Tip'
       );

    On Category:

    static $belongs_many_many = array(
    'Tips' => 'Tip'
    );

    Of course I have TipHolder... etc... but everything seems to work fine, except that when I save the Author and Province aren't saved with the rest of the data. My categories are though.

    I'm using

    $authorList = DataObject::get('Author');
    $fields->addFieldToTab("Root.Content.Main", new DropdownField('Author', 'Auteur', $authorList->toDropDownMap()), 'Content');

    ... and about the same for Province...
    in the getCMSFields function of Tips.

    So I'm probably overlooking something stupid here.

    Any ideas?

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Unsaved data Link to this post

    I think I'm running into the same problem. What version of SS are you using? I tried the following with RC1 and it failed to save. The has_one created FolderID on the WorkPage class after a db/build, but it doesn't ever save the ID using the dropdown field.

    You can get around it by using static $db = array('FolderID => 'Int') - however, that's only working around the issue, the has_one should be already doing this for you. Unless, you need to call the DropdownField('FolderID', 'Folder') ... but then this is a bit confusing if you've defined it as 'Folder' in the has_one relationship.

    EDIT: As suspected, the dropdown will work if you define the name as 'FolderID'. So, I edited the below example to work. I realise it's because the name in the database is FolderID and not Folder, so it wouldn't ever save properly because there is no 'Folder' column in the WorkPage table...

    I've filed it as a possible bug on open.silverstripe.com, unless someone otherwise states we're overlooking something here.

    [code php]
    class WorkPage extends Page {

    static $has_one = array(
    'Folder' => 'Folder'
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();

    if($folders = DataObject::get('Folder')) {
    $fields->addFieldToTab('Root.Content.Main', new DropdownField('FolderID', 'Folder', $folders->toDropdownMap()), 'Content');
    }

    return $fields;
    }

    }

    Cheers,
    Sean

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Unsaved data Link to this post

    I am using 2.1 rc 1 too.
    I'm having the same issue when using an OptionsetField.

    Gonna look into your solution and let you know if it works!

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Unsaved data Link to this post

    Yep, setting the name as 'ClassID' instead of 'Class' did the trick.

    A bit confusing though.

    1106 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.