I am having an issue with decorating the Member object and declaring a has_one relationship to another DataObject.
Firstly I extend the DataObjectDecorator adding a has_one relationship (AreaManagerMember ).
Secondly I add the matching relationship on the related DataObject (JSSRegion)
I then declare the Object::add_extension('Member', 'AreaManagerMember'); in config
run dev/build
checking the Member table there is no field for the relationship
I discovered the statement below at http://doc.silverstripe.org/framework/en/2.4/reference/dataobjectdecorator:
NOTE If you want to add has_one or db items to a particular class, then that class must have that static variable explicitly defined, even if it's just a blank array. For example, the decorator method above wouldn't work if you added to a class that didn't have static $has_one explicitly declared on the object. This is because of PHP's crappy support for statics.
I am not completely sure what this means as the Member object does have a static has_one
Any and all help would be greatly appreciated.
Classes In Question:
<?php
class AreaManagerMember extends DataObjectDecorator{
function extraStatics(){
return array(
$has_one = array(
'JSSRegion' => 'JSSRegion'
)
);
}
}
<?php
class JSSRegion extends DataObject
{
static $db = array(
'Name' => 'Varchar(255)',
'RegionID' => 'Int'
);
//Fields to show in the DOM table
static $summary_fields = array(
'Name' => 'Name',
'RegionID' => 'RegionID'
);
static $has_one = array(
'Manager' => 'AreaManagerMember'
);
static $has_many = array(
'Stores' => 'Store',
);