Hi everyone,
I know i can show dataobjects in a CTF that are assigned to one page by using the source filter, however i want the dataobject usable by a few different class files, and I'm not sure how to set up the dataobject's has_one relationship. here's what I have:
(code is in ProductCategory.php, ProductPage.php, and a few others that all extend Page)
$downloadfield = new ComplexTableField(
$this,
'RelatedDownloads',
'DownloadLink',
array(
'LinkName' => 'Name'
),
'getCMSFields',
"DownloadLink.DownloadlinkToPageID = {$this->ID}"
);
$downloadfield->setParentClass('ProductCategory');
$downloadfield->relationAutoSetting = true;
class DownloadLink extends DataObject {
static $db = array(
'LinkName' => 'Text'
);
static $has_one = array(
'Document' => 'File',
'DownloadLinkToPage' => 'Page' // (THIS WORKS AS 'ProductCategory' or 'ProductPage')
);
function getCMSFields() {
$fields = new FieldSet();
$fields -> push(new TextField("LinkName", "Name"));
$fields -> push(new ImageField('Document'));
return $fields;
}
}
I'm not sure how to set up the has_one relationship on the DownloadLink class.. I was hoping that the superclass of the ProductCategory and ProductPage classes (Page) would return records to the calling classes but nothing shows up in the CTF. data is created in the database, and the DownloadLink Dataobjects do have the correct 'DownloadLinkToPageID', and everything works if i change Page to ProductPage in the has_one relationship.
any thoughts?
thanks,
-Chris