7921 Posts in 1359 Topics by 933 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1299 Views |
-
ManyManyDataObjectManager doesn't save or update has_many items

30 March 2010 at 4:11am Last edited: 30 March 2010 4:12am
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?
-
Re: ManyManyDataObjectManager doesn't save or update has_many items

30 March 2010 at 4:40am
What version of DOM are you running?
-
Re: ManyManyDataObjectManager doesn't save or update has_many items

30 March 2010 at 4:54am
I downloaded "modules-dataobject_manager-r380.tar.gz".
-
Re: ManyManyDataObjectManager doesn't save or update has_many items

30 March 2010 at 5:17am
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.
-
Re: ManyManyDataObjectManager doesn't save or update has_many items

30 March 2010 at 5:29am
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.
-
Re: ManyManyDataObjectManager doesn't save or update has_many items

30 March 2010 at 9:40pm
UncleCheese, I really appreciate your very important information about the 2.3. branch of DOM. With this version everything works perfect now!
Thanks alot!
| 1299 Views | ||
|
Page:
1
|
Go to Top |

