Jump to:

1999 Posts in 1408 Topics by 613 members

Form Questions

SilverStripe Forums » Form Questions » Managing has_one relations in the CMS

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

Page: 1
Go to End
Author Topic: 666 Views
  • plucfortin
    Avatar
    Community Member
    2 Posts

    Managing has_one relations in the CMS Link to this post

    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.

  • Isaac Salt
    Avatar
    Community Member
    3 Posts

    Re: Managing has_one relations in the CMS Link to this post

    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

  • plucfortin
    Avatar
    Community Member
    2 Posts

    Re: Managing has_one relations in the CMS Link to this post

    HasOneComplexTableField seems to solve my problem.

    Thanks!!!

    666 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.