Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » DataObjectDecorator and has_many

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1772 Views
  • rob.s
    Community Member
    78 Posts

    DataObjectDecorator and has_many Link to this post


    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(

    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 ?

  • MarcusDalgren
    Community Member
    288 Posts

    Re: DataObjectDecorator and has_many Link to this post

    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.