1779 Posts in 582 Topics by 556 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 362 Views |
-
Managing has_one relations in the CMS

17 June 2012 at 3:14am Last edited: 17 June 2012 3:16am
Hi.
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.
Thanks.
-
Re: Managing has_one relations in the CMS

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:
http://doc.silverstripe.org/sapphire/en/reference/form-field-types#relations -
Re: Managing has_one relations in the CMS

18 June 2012 at 7:34am Last edited: 18 June 2012 7:37am
HasOneComplexTableField seems to solve my problem.
Thanks!!!
| 362 Views | ||
|
Page:
1
|
Go to Top |


