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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Unsaved data


Go to End


4 Posts   1523 Views

Avatar
dio5

Community Member, 501 Posts

15 September 2007 at 12:00pm

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?

Avatar
Sean

Forum Moderator, 922 Posts

15 September 2007 at 9:08pm

Edited: 15/09/2007 9:29pm

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

Avatar
dio5

Community Member, 501 Posts

16 September 2007 at 1:32am

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!

Avatar
dio5

Community Member, 501 Posts

16 September 2007 at 1:37am

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

A bit confusing though.