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.

Customising the CMS /

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

using ModelAdmin and customizing has_one relationship


Go to End


3 Posts   1380 Views

Avatar
Ajaxian

Community Member, 8 Posts

29 November 2012 at 12:17am

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

Avatar
zenmonkey

Community Member, 545 Posts

30 November 2012 at 2:18am

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

Avatar
Ajaxian

Community Member, 8 Posts

30 November 2012 at 5:08am

Edited: 30/11/2012 5:09am

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