Hello,
I have problem using relation between two DataObjects: ArticleObject and GameObject. Both objects are used within Holders (ArticlePage and SchedulePage) as has_many relations using the has_one in the Objects for the reverse relation. When editing a GameObject it should be possible to select a given Article for this Game. Using a DropDownField updates the GameObject table (the ID of the Article is written to the correct column) but the ArticleObject is never updated. The ID of the Game linking to the Article should also be stored there in order to find the way back. The other way the same when trying to establish the relation by editing the Article and linking to the Game.
I think I have done everything described in the tutorials. But why is the DropDownField not updating the related Object and how can I achieve this?
Thanks.
Here are the classes:
class GameObject extends DataObject {
static $has_one = array(
'Schedule' => 'SchedulePage',
'Article' => 'ArticleObject'
);
public function getCMSFields_forPopup() {
$fields = new FieldSet();
...
$articles = DataObject::get('ArticleObject', 'GameID = 0 OR GameID = ' . $this->ID, 'Created DESC', '', '10');
if (!$articles) {
$articleMap = null;
} else {
$articleMap = $articles->toDropDownMap('ID', 'Title');
}
$articleDropDown = new DropdownField('ArticleID', 'Bericht', $articleMap, $this, 'null', true);
$fields->push($articleDropDown);
}
}
class ArticleObject extends DataObject {
static $has_one = array(
'ArticleContainer' => 'ArticlePage',
'Game' => 'GameObject'
);
public function getCMSFields_forPopup() {
$fields = new FieldSet();
...
$games = DataObject::get('GameObject', 'ArticleID = 0 OR ArticleID = ' . $this->ID, 'Created DESC', '', '10');
if ($games) {
$gameMap = array();
foreach ($games as $game) {
$gameMap[$game->ID] = $game->GameIdent();
}
$gameDropDown = new DropdownField('GameID', 'Bericht', $gameMap, $this, 'null', true);
$fields->push($gameDropDown);
}
}
}