Multiple page Problem with DataObject and GroupedList

Silverstripe Version: 4.6


I created a Page with DataObject with GroupedList for monthly date grouping of properties ie booking dates the client has two properties so I used subsides module to admin both with separate domains (not relevant). When I add grouped list function to loop dataobject, both property dates appear together on both property pages. When I remove the grouplist function and just use dataobject loop it loops only that property dates but obviously not in month order can anyone see anything glaring that I have missed. How do I used grouped list to get each separate property dates not combined?


use SilverStripe\Forms\TimeField;
use SilverStripe\Forms\DateField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Versioned\Versioned;

class BookingDate extends DataObject 

private static $db = [
  		'MidWeekPrice' => 'Varchar',
  		'WeekendPrice' => 'Varchar',
  		'WeekPrice' => 'Varchar',
    	'BookDate' => 'Date',
    	'Booked' => 'Boolean',
    	'WKBooked' => 'Boolean',
    	'MWBooked' => 'Boolean',
        'SortOrder' => 'Int',	
 private static $has_one = [
    'DatePage' => DatePage::class,
  private static $table_name = 'BookingDate';
	private static $extensions = [
  private static $summary_fields = [
        'CreatedDMY' => 'Week Commencing',
    	'Booked.Nice' => 'Booked week?',
    	'WKBooked.Nice' => 'Booked weekend?',
    	'MWBooked.Nice' => 'Booked midweek?',
    	private static $versioned_gridfield_extensions = true;
        private static $default_sort = 'BookDate ASC';

  public function getCMSFields()
        $fields = FieldList::create(
        	TextField::create('WeekPrice','Price for the full week'),
        	CheckboxField::create('Booked', 'Check to mark as all week booked'),
            TextField::create('MidWeekPrice','Price for midweek'),
            CheckboxField::create('MWBooked', 'Check to mark as mid week booked'),
            TextField::create('WeekendPrice','Price for the weekend'),
            CheckboxField::create('WKBooked', 'Check to mark as weekend booked'),    
        return $fields;
     * Returns the month name this news item was posted in.
     * @return string
        public function getYearCreated() 
		        return date('F Y', strtotime($this->BookDate));

	use SilverStripe\CMS\Model\SiteTree;
	use SilverStripe\ORM\GroupedList;
	use SilverStripe\Forms\GridField\GridFieldConfig;
	use SilverStripe\Forms\GridField\GridFieldDataColumns;
	use SilverStripe\Forms\GridField\GridField;
	use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
	use SilverStripe\Forms\HTMLEditor\HTMLEditorField;

class DatePage extends Page 
	private static $db = [
		'MainContent' => 'HTMLText',
	private static $has_many = [
		'BookingDates' => BookingDate::class,
	private static $owns = [
	  public function getCMSFields()
		$config = GridFieldConfig_RecordEditor::create();
		$fields = parent::getCMSFields();
		$fields->addFieldToTab('Root.Main', HTMLEditorField::create('MainContent','Main content above dates'));
        $fields->addFieldToTab('Root.BookingDates', GridField::create(
            'Booking Dates on this page',

        return $fields;
     * Returns all news items, sorted by the month they were posted
     * @return GroupedList
        public function getGroupedBookingDatesByYear() 
        return GroupedList::create(BookingDate::get()->sort('BookDate'));

	<%-- Modules list grouped by the Month Posted --%>
		<% loop $GroupedBookingDatesByYear.GroupedBy("YearCreated") %> 
		  <div class="column3"> <h3>$YearCreated</h3>
			        <% loop $Children %>
			            <li><div class="Column1">$BookDate.Format('EEEE dd-MMM-y')</div>
			            <div class="Column2"><ul>
			          <% if $Booked %><li>WK: BOOKED </li><% else_if $WKBooked || $MWBooked %><% else %><li> WK: £$WeekPrice <a href="">Book</a></li><% end_if %>
			           <% if $WKBooked %><li>WE: BOOKED </li><% else_if $Booked  %><% else %><li>WE: £$WeekendPrice <a href="">Book</a></li><% end_if %>
			           <% if $MWBooked %><li>MW: BOOKED </li><% else_if $Booked  %><% else %> <li>MW: £$MidWeekPrice <a href="">Book</a></li><% end_if %></ul> </div></li> 
			        <% end_loop %>
		<% end_loop %>

Okay did a bit of a hack as I was getting frustrated and probably easy solution but it worked and actually worked better as I needed two different loops for different content.

created 2 functions

public function getGroupedBookingDatesByYear14() 
    return GroupedList::create(BookingDate::get()->filter([ 'DatePageID' => '14',])->sort('BookDate'));
  public function getGroupedBookingDatesByYear21() 
return GroupedList::create(BookingDate::get()->filter([ 'DatePageID' => '21',])->sort('BookDate'));

as I am only having 2 rental properties I hard coded the IDs in if statements and looped the children of the functions.

not great but works.