3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1534 Views |
-
DataObjectDecorator and has_many

6 August 2010 at 9:42pm Last edited: 6 August 2010 9:43pm
Hi,
i want to create an "Reminder" extension.
In our project are many custom DataObjects handled inside ModelAdmin.
To some of them i want to add a "Reminder" functionality.I decided to create a DataObjectDecorator, but i get errors.
Here are the code Snippets:
The Reminder DataObject itself:
class Reminder extends DataObject {
public static $db = array(
'Title' => 'Varchar(256)',
'Deadline' => 'SS_Datetime',
'Message' => 'HTMLText',
'Priority' => 'Enum("low,medium,high","medium")'
);public static $has_one = array(
);
}
The Decorator:
class ReminderExtension extends DataObjectDecorator {
function extraStatics() {
return array(
'has_many' => array(
'Reminders' => 'Reminder'
));}
public function updateCMSFields(FieldSet $fields) {
$table = new HasManyDataObjectManager($this->owner, 'Reminders', 'Reminder', array('Title' => 'Title'));
$fields->addFieldToTab('Root.Content.Reminders', $table);}
}And inside of some Dataobjects i deine the extension/the decorator
static $extensions = array(
'ReminderExtension'
);But when klicking inside ModelAdmin of an Dataobject to edit:
Warning: "array_flip() [function.array-flip]: The argument should be an array" at line 1334 of....../html/sapphire/core/model/DataObject.php
I am working with SS 2.4.1
Any ideas ?
-
Re: DataObjectDecorator and has_many

12 August 2010 at 12:05am
This is tricky since the way SS handles has_many. Adding has_many to a class doesn't actually do anything database wise, the system expects a has_one on the other side to know what to do and it's when the has_one is created that the correct stuff shows up in the db.
In short I'm not sure if this is doable in this manner.
| 1534 Views | ||
|
Page:
1
|
Go to Top |


