Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

ManyMany Relation


Go to End


5 Posts   1923 Views

Avatar
cardinale

Community Member, 23 Posts

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;
	} 	
}
?>

Avatar
UncleCheese

Forum Moderator, 4102 Posts

20 June 2009 at 8:19am

What problems are you having?

Avatar
cardinale

Community Member, 23 Posts

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'

Avatar
UncleCheese

Forum Moderator, 4102 Posts

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.

Avatar
cardinale

Community Member, 23 Posts

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 );