Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [resolved] many_many dont save ? i need help

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 966 Views
  • wardog
    Avatar
    Community Member
    9 Posts

    [resolved] many_many dont save ? i need help Link to this post

    I will try to explain as best as possible. The problem is as follows

    It is assumed that you should create a relationship many to many the problem is that it seems not to keep the relationship between DataObject and the page just kept in the DataObject.

    This should not be longer than another site should not be alone show me items that classname with some ID

    but apparently this is not so the code is as follows.

    File Iconografia.php

    Class Iconografia extends DataObject {
       
       public static $db = array();
       public static $has_one = array(
       'Imagen' => 'Image'
       );
       
       static $belongs_many_many = array(
    'Objs' => __CLASS__
    );

    /* For DataObjectManage */
    /*public function getImagen(){
       $image = $this->Imagen();
       return $image->CroppedImage(50,50);
    }

    public function getName() {
       $image = $this->Imagen();
       return $image->Name;
    }*/

       public function getCMSFields_forPopup() {
          $fields = new FieldSet();
          $ImgField = new ImageField('Imagen','Icono');
          $ImgField->setFolderName('Iconografia');
          $fields->push($ImgField);
          return $fields;
       }
       
    }

    File SolucionesHolder.php

    class SolucionesHolder extends Page {
       static $db = array ();

       static $has_one = array (
          'ImgHeader'         =>    'Image'
       );

       static $many_many = array(
          'MyIconografia'    =>   'Iconografia'
       );
       
       public function getCMSFields() {
          $fields = parent::getCMSFields();      
          $MyIco = new ManyManyComplexTableField(
              $this,
              'MyIconografia',
              'Iconografia',
              Array('Imagen'=>'Icono','Name'=>'Nombre'),
              'getCMSFields_forPopup'
          );
          
          $ImgField = new ImageField ( 'ImgHeader', 'Imagen de cabezera' );
          $ImgField->setFolderName ( 'Categorias' );
                 
          $fields->addFieldToTab("Root.Content.Iconografia",$MyIco);
          $fields->addFieldToTab("Root.Content.Main", $ImgField );
          return $fields;
       }
       
    }

    My SiteTree is Like this

    |-Site
    |-Solutions => PageClass
    \
    *|-- DataCenter => SolucionesHolder => many_many (Iconografia)
    *|-- Voice => SolucionesHolder => many_many (Iconografia)
    *\
    **|-- Product 1 => SolucionPage => => many_many (Iconografia)
    **|-- Product 2 => SolucionPage => => many_many (Iconografia)
    **|-- Product 3 => SolucionPage => => many_many (Iconografia)
    **|-- Product 4 => SolucionPage => => many_many (Iconografia)
    ....

    I hope to be clear in advance thank you very much

  • wardog
    Avatar
    Community Member
    9 Posts

    Re: [resolved] many_many dont save ? i need help Link to this post

    well actually this code was my mistake to select each item was not selecting duuu .. hehe thanks anyway ..

    Maybe you can take the code example to those who have no very clear how works many_many relationship

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