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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

SOLVED Dataobject with has_many Images, error on edit Dataobject

Go to End

2 Posts   3052 Views


Community Member, 175 Posts

6 November 2011 at 9:56am

I have a DO product:

class Product extends DataObject {

static $db = array(
   'name' => 'Varchar',
   'description' => 'HTMLText',
   'price' => 'Decimal(6,2)',

static $has_many = array(
   'Images' => 'MyImage'

public function getCMSFields_forPopup() {
   $images = new MultipleImageUploadField('Images', 'Images');
   $images->uploadFolder = 'Uploads/Produktbilder';
   return new FieldSet(
    new TextField('name', 'Produktbezeichnung'),
    new HtmlEditorField('description', 'Produktbeschreibung'),
    new TextField('price', 'Preis'),


and a MyImage:

class MyImage extends File {

static $has_one = array (
   'Product' => 'Product'


I added Product to a tab with Dataobjectmanager:

$fields->addFieldToTab("Root.Content.Produkte", new DataObjectManager(
          'name' => 'Produktbezeichnung',
          'description' => 'Produktbeschreibung',
          'price' => 'Preis'

Now I can add Products, and also the Images to the products. But when I wan to edit the Product:

[Warning] array_flip() expects parameter 1 to be array, null given
GET /admin/EditForm/field/Products/item/3/edit?SecurityID=337b36073e9f80cfe044df4c334598fce74b2fad&ctf[Products][start]=0&ctf[Products][per_page]=10&ctf[Products][showall]=0&ctf[Products][sort]=&ctf[Products][sort_dir]=&ctf[Products][search]=&ctf[Products][filter]=

Line 1334 in /var/www/vhosts/

1326       if(!$remoteClass) {
1327          throw new Exception("Unknown $type component '$component' on class '$this->class'");
1328       }
1330       if($fieldPos = strpos($remoteClass, '.')) {
1331          return substr($remoteClass, $fieldPos + 1) . 'ID';
1332       }
1334       $remoteRelations = array_flip(Object::combined_static($remoteClass, 'has_one', 'DataObject'));
1336       // look for remote has_one joins on this class or any parent classes
1337       foreach(array_reverse(ClassInfo::ancestry($this)) as $class) {
1338          if(array_key_exists($class, $remoteRelations)) return $remoteRelations[$class] . 'ID';
1339       }

what could be wrong here?


Community Member, 175 Posts

6 November 2011 at 10:08am


I forgot the has_one relation to CategoryPage ...