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

SS3 Get related has_one object in data object


3 Posts   697 Views


6 July 2013 at 2:53am (Last edited: 6 July 2013 2:53am), Community Member, 2 Posts

Hello there!

I'm trying to build a simple image gallery.

I created an GalleryImage DataObject that has a has_one relation to GalleryPage. I would like to be able to specify a folder name that is formed from the id and / or name of the related GalleryPage.

I know I can set the folder with


However…how do I access the properties of the related page in this context?


class BikeImage extends DataObject {

const TITLE_NAME = 'Title';
const SORT_ORDER_NAME = 'SortOrder';

private static $db = array(
self::TITLE_NAME => 'Varchar',
self::SORT_ORDER_NAME => 'Int',

// One-to-one relationship with bike page
private static $has_one = array(
'Image' => 'Image',
'GalleryPage' => 'GalleryPage'

public function getCMSFields() {
$fields = parent::getCMSFields();

$fields->removeFieldFromTab('Root.Main', 'GalleryPageID');

$custom_folder_name = 'default';

// $custom_folder_name = name / id of related gallery page
// how to access the properties of the related gallery page?

$uploadField = new UploadField('Image', _t('general.image', 'image'));
$fields->addFieldToTab('Root.Main', $uploadField);

return $fields;

// Tell the data grid what fields to show in the table
private static $summary_fields = array(
'ID' => 'ID',
self::TITLE_NAME => 'Title'


Thx for any pointers!


6 July 2013 at 10:35am Forum Moderator, 474 Posts

$this->GalleryPage() returns the object the has_one relates to.


11 July 2013 at 4:44am (Last edited: 22 July 2013 10:57pm), Community Member, 2 Posts



does return an object, but its ID is zero.

Could it be that the ID is only known after the record is saved?