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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Multiple DataObject instances in Page


Reply


480 Views

Avatar
ROlckers

Community Member, 8 Posts

15 February 2012 at 9:04am

This topic should probably exist in the General category so please move this if it is not relevant to the DataObjectManager.

I have a DataObject class called MyDataModel. I also have a page called MyPage which has a 'has_many' relationship with MyDataModel. The MyDataModel has a 'has_one' relationship with MyPage.

I use the DOM inside MyPage to manage MyDataModel's data.

My question is this: could I have multiple instances of MyDataModel inside the MyPage class? MyModel1's tab's data should contain only the data as loaded through MyModel1's tab. The same goes for MyModel2's tab etc.. Hope this makes sense.

My gut tells me this is not possible by doing it the way I describe below as when I performed a dev/build with the additional 'instances' to MyDataModel, nothing happened to the table structure.

class MyPage extends Page {

   static $has_many = array (
      'MyDataModel1' => 'MyDataModel',
      'MyDataModel2' => 'MyDataModel',
      'MyDataModel3' => 'MyDataModel',
      'MyDataModel4' => 'MyDataModel'
   );

   public function getCMSFields() {
      $fields = parent::getCMSFields();
      
      $fields->addFieldToTab("Root.Content.MyModel1", new DataObjectManager(
         $this,
         'MyDataModel1',
         'MyDataModel',
         array('Name'=>'Name'),
         'getCMSFields_forPopup'
      ));
      
      $fields->addFieldToTab("Root.Content.MyModel2", new DataObjectManager(
         $this,
         'MyDataModel2',
         'MyDataModel',
         array('Name'=>'Name'),
         'getCMSFields_forPopup'
      ));
      
      //... etc...
      
      return $fields;
   }

}