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.

Customising the CMS

CTF Source filter


2 Posts   1250 Views


15 January 2009 at 4:30am (Last edited: 15 January 2009 4:31am), Community Member, 95 Posts

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(
      'LinkName' => 'Name'
   "DownloadLink.DownloadlinkToPageID = {$this->ID}"
$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?


15 January 2009 at 8:21am Community Member, 95 Posts

I figured it out. Because DownloadLink was being used by multiple classes, and each calling class had the same tables, i made a superclass with the tables, and subclassed from there.