Hi all,
I'm on SilverStripe 2.3.6 and currently develop a little "download section". The model is really simple - i just extended the doc's "FileDataObjectManager" example (see http://doc.silverstripe.org/doku.php?id=modules:DataObjectManager). My Resource object has an extra "has_many" relationship to ResourceCategories. I am also using Translateable extension.
Here are my classes:
Resource.php
<?php
class Resource extends DataObject {
static $extensions = array(
"Translatable",
);
static $db = array (
'Name' => 'Text',
'Description' => 'Text'
);
static $has_one = array (
'Attachment' => 'File',
'ResourcePage' => 'ResourcePage',
);
static $many_many = array (
'ResourceCategories' => 'ResourceCategory',
);
public function getCMSFields_forPopup() {
$categoriesTable = new ManyManyDataObjectManager(
$this,
'ResourceCategories',
'ResourceCategory',
array(
'Name' => 'Name',
'Description' => 'Description'
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
);
return new FieldSet(
new TextField('Name'),
new TextareaField('Description'),
$categoriesTable,
new FileIFrameField('Attachment')
);
}
}
?>
ResourceCategory.php
<?php
class ResourceCategory extends DataObject {
static $extensions = array(
"Translatable"
);
static $belongs_many_many = array(
'Resources' => 'Resource'
);
static $db = array (
'Name' => 'Text',
'Description' => 'Text'
);
public function getCMSFields_forPopup() {
return new FieldSet(
new TextField('Name'),
new TextareaField('Description')
);
}
}
?>
When i upload a Resource, I am able to add a ResourceCategory which is saved but the relation is not set. Table "Resource_ResourceCategories" remains empty.
I also tried to replace ManyManyDataObjectManager with ManyManyComplexTableField but this didn't help either.
Has anyone an idea on how to solve this?