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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

CMS edit has_one related object's data in same popup


Go to End


965 Views

Avatar
ismooth

Community Member, 25 Posts

31 August 2012 at 9:15pm

Hi,

I have two objects, say:

class MyObjA extends DataObject {
  has_one = array('objB' => 'MyObjB');
}

class MyObjB extends DataObject {
  has_many = array('objsA' => 'MyObjA');
}

what I woul like to be able is when in CMS popup editing MyObjA, to have additional tab with loaded MyObjB with all it's data. I tried doing this in MyObjA:

function getCMSFields(){
  $f = parent::getCMSFields();
  $f->addFieldsToTab('Root.objB', $this->objB()->getCMSFields());
  return $f;
}

but all I get is bunch of empty fields. I also tried explicitly fetching related object by it's ID, but same result.
Is there a way to have in the same popup an object and it's has_one related object, so that I can edit them both (not edit the relation, but their data) at the same time?