Hello,
pretty basic question, but i've only worked with has_one relations.
I have a dataobject linked to a page with a has_one relation like, but now i want to link the dataobject to two, or in the future three, different page types. The idea: I don't want a relation between the files under PageTypeA & PageTypeB. I just want to use the Video.php code again. So when i create a PageTypeB, i don't want to see the files in the manager that were created under PageTypeA.
The DataObject:
<?php
class Video extends DataObject
{
static $db = array (
'Title' => 'Varchar(100)',
'Width' => 'Varchar(100)',
'Height' => 'Varchar(100)',
'Description' => 'Text'
);
static $has_one = array (
// Make sure this comes first
'PageTypeA' => 'PageTypeA',
'File' => 'File'
);
}
The PageTypeA:
<?php
class PageTypeA extends Page {
static $db = array(
);
static $has_one = array(
);
static $has_many = array (
'Videos' => 'Video'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Videos", new FileDataObjectManager(
$this,
'Videos', // relation name
'Video', // class name of the DataObject
'File', // name of the file relation in the DataObject
array('Title' => 'Title','Width' => 'Width','Height' => 'Height','Description' => 'Description'),
new FieldSet(
new TextField('Title'),
new TextField('Width'),
new TextField('Height', 'Height'),
new TextareaField('Description')
)
));
return $fields;
}
}
class PageTypeA_Controller extends Page_Controller {
}
Now i want to link this DataObject as well to PageTypeB.
How do i do this?
Like this?
The DataObject:
<?php
class Video extends DataObject
{
static $db = array (
'Title' => 'Varchar(100)',
'Width' => 'Varchar(100)',
'Height' => 'Varchar(100)',
'Description' => 'Text'
);
static $has_one = array (
'File' => 'File'
);
static $has_many = array (
'PageTypeA' => 'PageTypeA',
'PageTypeB' => 'PageTypeA',
);
}