17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1738 Views |
-
getComponents() problem (one to many relationship)

24 November 2007 at 7:50am Last edited: 25 November 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;
}...
-
Re: getComponents() problem (one to many relationship)

24 November 2007 at 1:04pm
Hello there,
Might I enquire what version of SilverStripe you're using?
Cheers,
Sean -
Re: getComponents() problem (one to many relationship)

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
-
Re: getComponents() problem (one to many relationship)

25 November 2007 at 12:56am Last edited: 25 November 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 ?
| 1738 Views | ||
|
Page:
1
|
Go to Top |


