Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Extending Extensions loses ParentId

Go to End

4 Posts   1081 Views


Community Member, 63 Posts

22 March 2014 at 10:23pm

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; 



Community Member, 63 Posts

23 March 2014 at 9:15pm

Edited: 23/03/2014 9:18pm

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


Community Member, 63 Posts

23 March 2014 at 10:21pm

Edited: 23/03/2014 10:33pm

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 ?


Community Member, 63 Posts

26 March 2014 at 8:00pm

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?