Jump to:

23376 Posts in 18214 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » ModelAdmin and double has_many coupling

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

Page: 1
Go to End
Author Topic: 492 Views
  • esakrielaart
    Avatar
    Community Member
    54 Posts

    ModelAdmin and double has_many coupling Link to this post

    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

  • skorp
    Avatar
    Community Member
    6 Posts

    Re: ModelAdmin and double has_many coupling Link to this post

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

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: ModelAdmin and double has_many coupling Link to this post

    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

  • esakrielaart
    Avatar
    Community Member
    54 Posts

    Re: ModelAdmin and double has_many coupling Link to this post

    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 tutorial 5 on DataObject relationships. 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

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: ModelAdmin and double has_many coupling Link to this post

    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)

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