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:

Form Questions /

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

Managing has_one relations in the CMS

Go to End

3 Posts   1253 Views


Community Member, 2 Posts

17 June 2012 at 3:14am

Edited: 17/06/2012 3:16am


If a SiteTree model is related to another model with a has_many relation, it's easy to manage in the CMS: we override getCMSFields() in order to add a new ComplexTableField in a new Tab. This has been clearly documented.

However it is not clear to me how we should handle has_one relations. I know that in this situation, we can create a new DropdownField to choose an object (of class OtherModel) and place it in the FieldSet returned by getCMSFields. I tried this and it worked, but I found that the problem with this approach is that the object we want to relate to our SiteTree object must exist first. Hence, this approach forces the end user to use another tool (like ModelAdmin) to create its objects first, then go back to the SiteTree object edit form and select the right object. Doing that is not too complicated for me, but it is for our clients.

What I'd like to know is if Silverstripe provides a built-in solution for this problem. Such a solution could be, for example, a "create or select" field which would allow us to select a preexisting 'OtherModel' object in a DropdownField or to click a button to open a popup form to create a new 'OtherModel' object. I'd like to know if I have to create new subclasses, extend or modify Silverstripe to get a solution for my problem.


Isaac Salt

Community Member, 3 Posts

17 June 2012 at 2:13pm

You could look at using one of the relational forms which allows a CMS to assign a DataObject to a Page and edit/create/delete them:


Community Member, 2 Posts

18 June 2012 at 7:34am

Edited: 18/06/2012 7:37am

HasOneComplexTableField seems to solve my problem.