Hello somebody,
I'm having trouble understanding the DataObject $hase_one relation ship. I'm using Silverstrip 3.05
The following is what i'm trying to accomplish:
I'm trying to create a page where i can add projects thru a GridField and present them thru a slide show. Every slide show has a variable number of pictures so i thought i would need a DataObject within a DataObject.
I'm using three Page types.
- Project (a page that has a relation with Slideshow)
- Slideshow (a Dataobject witch has a description and title of the project)
- Images (a DataObject witch has a relation with Project so i can add as many picturs to the slideshow)
ProjectPage and Project works but i cant add as many pictures as i want.
Below is my code example, i'm not using pictures yet, i'm just trying to understand howe it works.
----------------------------------------------------------------------------------------
<?php
class Project extends Page {
static $has_many = array(
'Slideshows' => 'Slideshow'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$config = GridFieldConfig_RelationEditor::create();
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
'Name' => 'Name',
'Project.Title'=> 'Project'
));
$SlideshowsField = new GridField(
'Slideshows',
'Slideshow',
$this->Slideshows(),
$config
);
$fields->addFieldToTab('Root.Slideshows', $SlideshowsField);
return $fields;
}
}
class Project_Controller extends Page_Controller {
}
-----------------------------------------------------------------------------------
<?php
class Slideshow extends DataObject {
static $db = array(
'Name' => 'Varchar',
'University' => 'Varchar',
);
static $has_one = array(
'Project' => 'Project'
);
static $has_many = array(
'Images' => 'Images'
);
}
------------------------------------------------------------------------------------
<?php
class Images extends DataObject {
static $db = array(
'Something1' => 'Varchar',
'Something2' => 'Varchar',
);
static $has_one = array(
'Slideshow' => 'Slideshow'
);
}