Jump to:

5521 Posts in 1734 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Data relations

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

Page: 1
Go to End
Author Topic: 1051 Views
  • Capt. Morgan
    Avatar
    Community Member
    30 Posts

    Data relations Link to this post

    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
    Avatar
    Community Member
    30 Posts

    Re: Data relations Link to this post

    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.

    1051 Views
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.