Hi guys,
I'm currently trying to use the DataObjectManager in the following way:
(1) I have a class NewsItem:
class NewsItem extends DataObject {
static $db = array(...);
static $has_one = array("NewsStream" => "NewsStream", ...);
}
(2) A class NewsStream:
class NewsStream extends DataObject {
static $db = array(...);
static $has_many = array(..., "NewsItems" => "NewsItem");
}
(3) And I have a Decorator to add NewsStreams to pages:
class NewsStreamDecorator extends DataObjectDecorator {
function extraStatics() {
return array("has_one" => array("NewsStrom" => "NewsStream"));
}
public function updateCMSFields(FieldSet $fields) {
if(($streams = DataObject::get("NewsStream")) != null)
$fields->addFieldToTab("Root.Content.News", new DropdownField("NewsStromID", "Neuigkeiten Strom", $streams->toDropdownMap("ID", "Title")));
else
$fields->addFieldToTab("Root.Content.News", new LiteralField("Message", "Keine Newsströme im System vorhanden!"));
if(($stream = $this->owner->NewsStrom()) != null ) {
$dom = new DataObjectManager($this->owner, "NewsStrom->NewsItems", "NewsItem", array("Title" => "Titel", "ForceHomepage" => "Auf Homepage anzeigen", "ShowGallery" => "Hat eine Galerie"), "getCMSFields_forPopup", "NewsStreamID = ".$stream->ID);
$fields->addFieldToTab("Root.Content.News", $dom);
}
return $fields;
}
}
If I know try to add NewsItems via the DOM they will get written without a NewsStreamID. Any idea how to solve this problem?
thanks in advance,
gieser