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.

Data Model Questions

Save property to ManyManyList


5 Posts   450 Views


13 August 2013 at 7:27am Community Member, 20 Posts


I am a little confused. I have a CustomerproductPage, a Custom ProcuctfotoForm, a DataObject Customerproduct, a DataObjec Extension for many_many Images (Customerproduct_ProdcutphotoExtension) and another CustomerproductDetail Page for showing details, saving, editing.

Now I have a method like this on my DataObject Customerproduct

public function Productphoto() {
   return $this->getManyManyComponents(
      "\"Customerproduct_Productphoto\".\"ID\" ASC"


Actuall, this is ok..I can receive on two pages the relation Data. But this is the problem. I just can save on one Page to the relation the Images but on the other page not. It does just show, means I get by sql query the relation data, but I can't save it

on the CustomerproductPage (custom form of the page) it works, I have this:

$productobj = DataObject::get_by_id('Customerproduct', $productID);
$productobj->Productphoto()->CustomerproductID = $productID;
$productobj->Productphoto()->ImageID = $fileID;
$arr = array($productobj->ID,$productobj->Productphoto()->ImageID = $fileID);

But on the CustomerproductDetail Page I try to do the same, it does not work.

I receive also by Debug the right Data from this manymanylist
$list = new ManyManyList('Customerproduct_Productphoto','Customerproduct', 'ID', 'CustomerproductID');

My question is now, how can I save on the second Page, the detail Page, my Data which I receive through a form?

When I try this by says the following;

$product = Customerproduct::get()
         ->where("\"ID\" = '$id'");

// $list = new ManyManyList('Customerproduct_Productphoto','Customerproduct', 'ID', 'CustomerproductID');

$test = $product->Productphoto()->ImageID;


[User Error] Uncaught Exception: Object->__call(): the method 'productphoto' does not exist on 'DataList'

Can anyone help?

Thanks a lot!


13 August 2013 at 8:12am (Last edited: 13 August 2013 8:13am), Community Member, 20 Posts

Now it does on both pages not work anymore. I have to remark this is for frontend. In the backend it is no problem. But the clients shall have the possibility to load images to a product.

I am not sure how the correct way is to code this manymany relations


13 August 2013 at 8:14pm Forum Moderator, 1091 Posts

At a quick glance I see:

$product = Customerproduct::get()
         ->where("\"ID\" = '$id'");

xxx::get() always returns a DataList (a set of DataObjects) even if it only contains one object. To actually get the object itself you could

$product = Customerproduct::get()->byID($id);


13 August 2013 at 11:49pm Community Member, 20 Posts

Thanks very much for your answer. That was a problem too.

I found out that the other problem is acutally not the relation. It is because in my second page, it does not save the ID of the File Image.

I have several other forms, with Ajax, without Ajax, they work, but here on his page it does not work anymore. I changed it to a has_one relation, just one picuture, but the same. It doesn't save me the ID of the attached Image. It looks all the same like other who are working. This is realy confusing.

I flushed a lot of times..I don't think it is the cache.

How can I get in another way the ID? This here works not anymore, and just with saveIntoForm works also not, I have no ID of the picture.

$up =new Upload();
$img = Object::create('Image');

$up->loadIntoFile($photo, $img, 'Kundenbilder/Kundenbilder'.$memberID);
$record = $img->ID;
$fileID = $record;

$productobj->ProductphotoID = $fileID ;

Thanks for your help!


14 August 2013 at 6:38am Community Member, 20 Posts


I am not sure...but can it be, that when I have two forms, one as a custom form, the other as an form on a page with the same name of uploadfield, that it doesn't send the record ID of the insert in the File Class?

Now I tried my custom form in the second page, means, took the same...and see saves me the ID of the Photo in my Customerproduct Class.

Is there a rule or something that you can't use the same name of uploadfield in different named forms?

Tanks for your answer.