Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » getComponents() problem (one to many relationship)

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

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

Page: 1
Go to End
Author Topic: 1938 Views
  • Fuzz10
    Avatar
    Community Member
    787 Posts

    getComponents() problem (one to many relationship) Link to this post

    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;
       }

    ...

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: getComponents() problem (one to many relationship) Link to this post

    Hello there,

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

    Cheers,
    Sean

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: getComponents() problem (one to many relationship) Link to this post

    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

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: getComponents() problem (one to many relationship) Link to this post

    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 ?

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