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:

Archive /

Our old forums are still available as a read-only archive.

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

getComponents() problem (one to many relationship)

Go to End

4 Posts   2449 Views


Community Member, 791 Posts

24 November 2007 at 7:50am

Edited: 25/11/2007 3:22am


I can't get getComponents() to behave. Can somebody spot the problem ?

The class VestigingenPage has many FaciliteitTijdstip. FacilitijdTijdstip has just one Vestigingenpage. The relationship works. I can add rows to the database and the Foreigh key to Vestigingenpage gets stored properly.

I'd like to limit the list of the FaciliteitTijdstip so it only shows the entry's which are linked to the current Vestiging (Foreign key in the database is called VestigingID).

No matter what value I give the VestigingID in the GetComponents() call. It just does not limit the list and shows all records.

HELP !!! ;-)

Class FaciliteitTijdstip:

class FaciliteitTijdstip extends DataObject {
	static $db = array(
	'Value1' => "Text",
	'Value2' => "Text"
   static $has_one = array(
      'Vestiging' => 'VestigingenPage'

Class VestigingsPage:

class VestigingenPage extends Page {

    static $has_many = array(
      'FaciliteitTijdstippen' => 'FaciliteitTijdstip',

 function FaciliteitTijdstippenFiltered() {
        return $this->getComponents("FaciliteitTijdstippen", "VestigingID=$this->ID");
function getCMSFields() {
		$fields = parent::getCMSFields();

	   $tablefield = new HasManyComplexTableField(
	    	'Value1' => 'FirstName',
	    	'Value2' => 'Family Name',
       $fields->addFieldToTab( 'Root.Content.Tijdschema', $tablefield );
	   return $fields;


Forum Moderator, 922 Posts

24 November 2007 at 1:04pm

Hello there,

Might I enquire what version of SilverStripe you're using?



Forum Moderator, 922 Posts

24 November 2007 at 4:59pm

I just ran your code through and discovered something - it's doing a filter of 'VestigingID = 13 AND VestigingID = 13' twice, so in other words, the normal has_many is filtering by VestigingID anyways...



Community Member, 791 Posts

25 November 2007 at 12:56am

Edited: 25/11/2007 3:39am

Hi Sean,

Thanks for your reply. I'm using RC3.

I can't figure out why it is not filtering (it's displaying all the records).

It seems it doesn't matter what the filter does, it just keeps showing all records. Argh... ;-)

I fixed it using the "sourcefilter" parameter on HasManyComplexTableField, but that is not the correct way to do it I presume ?