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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Multiple DataObject instances in Page

Go to End



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(
		$fields->addFieldToTab("Root.Content.MyModel2", new DataObjectManager(
		//... etc...
		return $fields;