Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » multiple manymany DOM : sortable jointable problem

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 366 Views
  • El Mich
    Avatar
    Community Member
    8 Posts

    multiple manymany DOM : sortable jointable problem Link to this post

    Hello,
    I have a setup where I 'tag' files with my product objects by a many_many, and in an other many_many I select which of these files should be shown on the product page. Like this:

    class FileDecorator extends DataObjectDecorator {
    function extraStatics() {
    return array(
    'belongs_many_many' => array(
    'Files' => 'Product',
    'AttachedFiles' => 'Product'
    ));
    }

    class Product extends DataObject {
    static $many_many = array(
    'Files' => 'File',
    'AttachedFiles' => 'File'
    );

    for both relations I use the DOM, with sortable extension:

    $FilesSelect = new ManyManyFileDataObjectManager(
    $this,
    'Files'
    'File'
    );

    and for the AttachedFiles, I first get a list of all files (ID's) tagged with this product and use this as a filter in the where clause:

    $TaggedFilesIdString = $this->getTaggedFilesIds();
    $AttachedFilesSelect = new ManyManyFileDataObjectManager(
    $this,
    'AttachedFiles',
    'File',
    $sourceFilter = "File.ID in($TaggedFilesIdString));

    Sortable extensions are configurated like this:

    SortableDataObject::add_sortable_many_many_relation("Product", "Files");
    SortableDataObject::add_sortable_many_many_relation("Product", "AttachedFiles");

    All works great, I can tag my files with products, I can sort these tagged files independently for each product, I can also select from the filtered list in the AttachedFiles DOM, but, if I change the sortorder on the AttachedFiles DOM it does not get stored.

    I did notice that upon sorting the AttachedFiles, the SortOrder field on the Product_Files table is updated, instead of the SortOrder field on the Product_AttachedFiles join table.

    How should I do this?
    Thank you!

    366 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.