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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

ModelAdmin and double has_many coupling


Reply


5 Posts   529 Views

Avatar
esakrielaart

Community Member, 56 Posts

5 November 2011 at 4:07am

Hello,

I experience the following problem. I have a class that has_many of another class which has another has_many to yet another class. All classes just store things like texts, no special references to other dataobjects are used. I use ModelAdmin to control the first class.

Now everything seems to be working, however in the ModelAdmin interface, the last class does not show an Add button (in the automatically generated popupfield).

So schematically I have

Class I
..has_many Class II

Class II
.. has_one Class I
.. has_many Class III

Class III
.. has_one Class II

I think many people are struggeling with this, and I hope that this schematical sketch and the wished solution will help not only me but more people around.

Thanks in advance!
Maurice

Avatar
skorp

Community Member, 6 Posts

7 January 2012 at 1:08am

Hi, i have the same problem.
Did you find a solution for this problem?

Avatar
swaiba

Forum Moderator, 1798 Posts

7 January 2012 at 2:02am

Edited: 07/01/2012 4:13am

I always had this issue, scaffolding circular relationships. I tackle it in several ways...
1) model redesign
2) modify getCMSFields code to remove the scaffolding relations and creating them in a custom way
3) hack the code to not use the ORM and crate my own form fields

Avatar
esakrielaart

Community Member, 56 Posts

7 January 2012 at 3:40am

Hi,

it's a while ago so I can't tell the precize solution, but the methods mentioned by swaiba are what I use currently to, espacially the first and second method. If you encounter a problem as I described above you must definitely wonder if your model is build logically, so if there isn't any more sufficient way to build it.
Secondly, try to overrun the default getCMSFields, as also properly explained in the tutorials like [url='http://doc.silverstripe.org/sapphire/en/tutorials/5-dataobject-relationship-management']tutorial 5 on DataObject relationships[/url]. I can't immediately share knowledge on the third way mentioned by swaiba, but I can confirm that the first two are for me always enough to put focus on.

Friendly regards,
Maurice

Avatar
swaiba

Forum Moderator, 1798 Posts

7 January 2012 at 4:14am

3) hack the code to not use the ORM and crate my own form fields

I wouldn't advise this - I have only done this in the case of double many_many relationships (which are also problematic)