7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » ManyMany Relation
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: | 1139 Views |
-
ManyMany Relation

20 June 2009 at 7:48am
Hello,
I have some problems to show only a result list of a many_many-relation (without checkboxes and only the permission to 'show') with the DataObjectManager. I tried like this but it don't work. Can someone help me?<?php
class BehandlungsListe extends DataObject {static $db = array(
'Title' => 'Varchar(255)',
'Name_de' => 'Varchar(255)'
);
static $belongs_many_many = array(
'Anfragen' => 'Anfragen'
);
}class Anfragen extends DataObject {
static $many_many = array(
'BehandlungsListe' => 'BehandlungsListe'
);function getCMSFields() {
$fields = parent::getCMSFields();$AerzteTable = new DataObjectManager(
$this, 'BehandlungsListe', 'BehandlungsListe', null, null, "Anfragen_BehandlungsListe.AnfragenID = {$this->ID}");$AerzteTable->setPermissions(array("show"));
$fields->addFieldToTab( 'Root.Main', $AerzteTable );
return $fields;
}
}
?> -
Re: ManyMany Relation

20 June 2009 at 8:25am
I get this error:
[User Error] Couldn't run query: SELECT `BehandlungsListe`.*, `BehandlungsListe`.ID, if(`BehandlungsListe`.ClassName,`BehandlungsListe`.ClassName,'BehandlungsListe') AS RecordClassName FROM `BehandlungsListe` WHERE (Anfragen_BehandlungsListe.AnfragenID = 1) ORDER BY SortOrder ASC LIMIT 0,10 Unknown column 'Anfragen_BehandlungsListe.AnfragenID' in 'where clause'
-
Re: ManyMany Relation

20 June 2009 at 8:30am
You're not using the DataObjectManager correctly. It's meant to manage the relationships of DataObjects to Pages -- not other DataObjects. If you want to manage a many-many relation between two dataobjects, you need to use a CheckboxSetField in the popup of a DataObjectManager.
-
Re: ManyMany Relation

20 June 2009 at 8:50am
Tank You for the help.
I use it in the ModelAdmin and not in a Popup and my target is to get a simple listing with the results of the relation. this script is working but I get all the spells in the 'BehandlungsLsite' and i want only the results of the relation.
$AerzteTable = new ComplexTableField( $this,'BehandlungsListe', 'BehandlungsListe' );
$AerzteTable->setPermissions(array("show"));
$fields->addFieldToTab( 'Root.Main', $AerzteTable );
| 1139 Views | ||
|
Page:
1
|
Go to Top |

