Jump to:

5521 Posts in 1733 Topics by 1220 members

Customising the CMS

SilverStripe Forums » Customising the CMS » using ModelAdmin and customizing has_one relationship

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

Page: 1
Go to End
Author Topic: 445 Views
  • Ajaxian
    Avatar
    Community Member
    8 Posts

    using ModelAdmin and customizing has_one relationship Link to this post

    Hi,
    I have set up a class which:
    # deals with 2 models : A and B, A has_many B, and B has_one A
    # extends ModelAdmin

    When I do a dev/buil, all things look good.
    I have a gridfield for A, a Tab for B.
    When I go in Pane B (page under Tab B) and when I click on "Add B" for adding a new object, then I have the good attributes of my B model

    BUT beacuse of the has_one relationship that B has with A I get a DropDonwList in which SilverStripe gathers the A existing model with their ID displayed.
    I would like to get the names of the A instances instead of the Id but I'm unaware how to achieve this.

    One can't add a B object related to a A already existing object by selecting its Id number. Would be great to select the name of the A instance.

    Do someone know how to achieve this ?

    Thanks

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: using ModelAdmin and customizing has_one relationship Link to this post

    Add the drop down field manually and map the DataObject. Take alook at the DropdownField documentation for an example. http://api.silverstripe.org/3.0/forms/fields-basic/DropdownField.html

  • Ajaxian
    Avatar
    Community Member
    8 Posts

    Re: using ModelAdmin and customizing has_one relationship Link to this post

    Thanks to reply and help me.

    I solved the problem by doing the way you described.
    We have to map the Id of the records to the Name

    And everything works great.

    The deeper I go into SS, the more I think it is a great framework. Well Designed.

    Nice day

    445 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.