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.

Archive /

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

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

getComponents() problem (one to many relationship)


Reply


4 Posts   2008 Views

Avatar
Fuzz10

Community Member, 787 Posts

24 November 2007 at 7:50am

Edited: 25/11/2007 3:22am

Hi..

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(
$this,
'FaciliteitTijdstippenFiltered',
'FaciliteitTijdstip',
array(
       'Value1' => 'FirstName',
       'Value2' => 'Family Name',
),
'getCMSFields_forPopup'
);

$fields->addFieldToTab( 'Root.Content.Tijdschema', $tablefield );
    return $fields;
   }

...

Avatar
Sean

Forum Moderator, 922 Posts

24 November 2007 at 1:04pm

Hello there,

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

Cheers,
Sean

Avatar
Sean

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

Sean

Avatar
Fuzz10

Community Member, 787 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 ?