Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Extending Extensions loses ParentId

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

Page: 1
Go to End
Author Topic: 477 Views
  • wildflower1975
    Avatar
    Community Member
    59 Posts

    Extending Extensions loses ParentId Link to this post

    I'm modifying the event calendar on SS 3.1.3 and adding a ticket field to the events, so

    NewCalendar extends Calendar which extends Page
    NewCalendar $has_many NewEvent

    NewEvent extends CalendarEvent which extends Page
    NewEvent has a Cost and $has_many NewEventDateTime

    NewEventDateTime extends CalendarDateTime which extends DataObject
    NewEventDateTime has a TicketsAvailable and $has_one NewEvent

    I can view each of the page types in the backend CMS and they show in the Site tree, and if I type the urls of the NewEvents directly they show on the front end, however the NewEvents aren't showing in the NewCalendar's "Jump to Month' widget

    In the DB it looks like the ParentIDs are missing for the instances of my New Extensions, so the parent CalendarDateTime doesn't link to the corresponding parent CalendarEvent although the records are there.

    How do I explicitly join them?

    I assume it's something like this, but it doesn't look to work (and I'm not getting any error messages from it)

    public function getCMSFields() {
    .....

    if(!$this->ParentID) {
    $fields->push(new HiddenField("ParentID", "ParentID", Controller::curr()->CurrentPageID()));
    }
    return $fields;
    }

    thanks

  • wildflower1975
    Avatar
    Community Member
    59 Posts

    Re: Extending Extensions loses ParentId Link to this post

    So I've found the query that should be selecting the Events and sending them to the Template on the front end,
    Line 246 of Calendar.php
    Debug::message("the sql is :". $list->sql() );

    The query knows the EventIDs of the events that should be shown for this NewCalendar Instance but the EventID column is 0 for these NewCalendarDateTime rows.

    So when these records are created/edited the EventID isn't being populated...

    These CalendarDateTime records are being managed in a GridField in the back end CMS

  • wildflower1975
    Avatar
    Community Member
    59 Posts

    Re: Extending Extensions loses ParentId Link to this post

    So to get it to work I have to put a Hidden field in the NewCalendarDateTime getCMSFields function to force the EventID into the database

    public function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->push(new NumericField('TicketsAvailable', _t('CalendarDateTime.TICKETS','Tickets Available')));      
    //      Debug::message(" the parent is : ".$this->ParentID );
          $fields->push(new HiddenField("EventID", "EventID", Controller::curr()->CurrentPageID()));
          
          return $fields;
       }

    it looks like the notion of the Parent doesn't hold for this structure or extending an extension of a DataObject doesn't get a ParentID handed down to it.

    Do I need a getParentID and setParentID function in my extension's Class ?

  • wildflower1975
    Avatar
    Community Member
    59 Posts

    Re: Extending Extensions loses ParentId Link to this post

    So when trying to display Registrations in the backend CMS, I've had to copy 2 functions from the DBField Object

    forTemplate() and XML()

    public function forTemplate()   {
          return $this->XML();
       }
       public function XML(){
          return Convert::raw2xml($this->value);
    }

    I've had to add these functions to the NewCalendarDateTime classes, I would've thought these should be inherited from the GrandParent classes also?

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