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.

Data Model Questions /

[resolved] many_many dont save ? i need help


Reply


2 Posts   1010 Views

Avatar
wardog

Community Member, 9 Posts

14 August 2010 at 10:45am

Edited: 18/08/2010 3:48pm

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

Avatar
wardog

Community Member, 9 Posts

18 August 2010 at 3:47pm

Edited: 18/08/2010 3:50pm

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