Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » ManyManyDataObjectManager doesn't save or update has_many items

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: 1412 Views
  • cake
    Avatar
    Community Member
    19 Posts

    ManyManyDataObjectManager doesn't save or update has_many items Link to this post

    Hi all,

    I'm on SilverStripe 2.3.6 and currently develop a little "download section". The model is really simple - i just extended the doc's "FileDataObjectManager" example (see http://doc.silverstripe.org/doku.php?id=modules:DataObjectManager). My Resource object has an extra "has_many" relationship to ResourceCategories. I am also using Translateable extension.
    Here are my classes:

    Resource.php

    <?php
    class Resource extends DataObject {

    static $extensions = array(
    "Translatable",
    );

    static $db = array (
    'Name' => 'Text',
    'Description' => 'Text'
    );

    static $has_one = array (
    'Attachment' => 'File',
    'ResourcePage' => 'ResourcePage',
    );

    static $many_many = array (
    'ResourceCategories' => 'ResourceCategory',
    );

    public function getCMSFields_forPopup() {
    $categoriesTable = new ManyManyDataObjectManager(
    $this,
    'ResourceCategories',
    'ResourceCategory',
    array(
    'Name' => 'Name',
    'Description' => 'Description'
    ), // Headings
    'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
    );

    return new FieldSet(
    new TextField('Name'),
    new TextareaField('Description'),
    $categoriesTable,
    new FileIFrameField('Attachment')
    );
    }

    }
    ?>

    ResourceCategory.php

    <?php
    class ResourceCategory extends DataObject {

    static $extensions = array(
    "Translatable"
    );

    static $belongs_many_many = array(
    'Resources' => 'Resource'
    );

    static $db = array (
    'Name' => 'Text',
    'Description' => 'Text'
    );

    public function getCMSFields_forPopup() {
    return new FieldSet(
    new TextField('Name'),
    new TextareaField('Description')
    );
    }
    }
    ?>

    When i upload a Resource, I am able to add a ResourceCategory which is saved but the relation is not set. Table "Resource_ResourceCategories" remains empty.

    I also tried to replace ManyManyDataObjectManager with ManyManyComplexTableField but this didn't help either.

    Has anyone an idea on how to solve this?

  • UncleCheese
    Avatar
    4085 Posts

    Re: ManyManyDataObjectManager doesn't save or update has_many items Link to this post

    What version of DOM are you running?

  • cake
    Avatar
    Community Member
    19 Posts

    Re: ManyManyDataObjectManager doesn't save or update has_many items Link to this post

    I downloaded "modules-dataobject_manager-r380.tar.gz".

  • UncleCheese
    Avatar
    4085 Posts

    Re: ManyManyDataObjectManager doesn't save or update has_many items Link to this post

    If you're on 2.3, you need to be using the 2.3 branch. I've made a ZIP file and posted it to a sticky in this forum. The downloads page doesn't support multiple versions of a module right now, so that's the best we can do. The ZIP files generated by SS are on the trunk now, which is the 2.4 branch.

    So you're using a nested DOM to manage your categories? You're checking them off before you save? It's not enough to just add them. A lot of people miss that step.

  • cake
    Avatar
    Community Member
    19 Posts

    Re: ManyManyDataObjectManager doesn't save or update has_many items Link to this post

    Ah, I see. I'll get the version you recommended.

    Indeed I am using a nested DOM within the modal view. When I have saved a category it shows up under the properties of the resource. Afer that I am checking and saving it. But there is nothing really saved.

  • cake
    Avatar
    Community Member
    19 Posts

    Re: ManyManyDataObjectManager doesn't save or update has_many items Link to this post

    UncleCheese, I really appreciate your very important information about the 2.3. branch of DOM. With this version everything works perfect now!

    Thanks alot!

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