Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Problems using DOM on has_many on a related DataObject

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 581 Views
  • gieser
    Avatar
    Community Member
    13 Posts

    Problems using DOM on has_many on a related DataObject Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Problems using DOM on has_many on a related DataObject Link to this post

    I'm not sure what the decorator is for?

    --------------------
    SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

  • gieser
    Avatar
    Community Member
    13 Posts

    Re: Problems using DOM on has_many on a related DataObject Link to this post

    ah sorry, didn't mention that. It is used to add NewsStream to those page types that need it. Didn't want to repeat myself you know.

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