Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » ManyMany Relation

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: 1244 Views
  • cardinale
    Avatar
    Community Member
    23 Posts

    ManyMany Relation Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: ManyMany Relation Link to this post

    What problems are you having?

  • cardinale
    Avatar
    Community Member
    23 Posts

    Re: ManyMany Relation Link to this post

    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'

  • UncleCheese
    Avatar
    4085 Posts

    Re: ManyMany Relation Link to this post

    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.

  • cardinale
    Avatar
    Community Member
    23 Posts

    Re: ManyMany Relation Link to this post

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

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