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:

Customising the CMS /

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

Data relations

Go to End

2 Posts   1406 Views

Capt. Morgan

Community Member, 30 Posts

27 February 2009 at 11:43am

Good evening SS community.

I'm getting started with SS and hope to find some help here. Yep, I'm totally stuck today.

I'm making an admin with some not too complex database relations.
Say I have a pricelist with one-to-many products.
Each product has got a many-to-many relationship to the attributes that define it.

The pricelist Extends siteTree and is where I want to add my products. The HasManyComplexTableField works great, even if I have the feeling I'm not totally in control yet :) How can I get the product-popup to set data for the product_attribute connection-table?

MY next problem will be that I wish to have the pricelist split in categories, maybe even in different tabs. And to do that without ID-conflicts. If anyone have some good advice for me there I'm very grateful.

Capt. Morgan

Community Member, 30 Posts

3 March 2009 at 2:06am

Edited: 03/03/2009 10:58pm

I will answer myself to maybe help someone else.

What I did eventually was to extend the HasManyComplexField class (to ProductComplexTableField) and override saveComplexTableField(). From there I save all the attributes I get from the form manually using $product->ProductAttributes()->add($attribute).

Although, for some reason it seems that $product->write() clears the attribute relations before they get saved to DB. That is why I first did $product->write() and then I added the attributes.

For my second problem. I solved it by registring the data relation once per category. If I used the same on all tabs, one would overwrite the other.

static $db = array(
'Category1Products' => 'Product',
'Category2Products' => 'Product'

This is not a very good solution because it will crash when I get a new Category. If anyone has a more dynamic way to solve this pls let me know.