Jump to:

5520 Posts in 1734 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » SS3: Many-to-many with extra field

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

Page: 1
Go to End
Author Topic: 970 Views
  • myak
    Avatar
    Community Member
    4 Posts

    SS3: Many-to-many with extra field Link to this post

    Hello,

    I'm very new to SS but I love it already. I'm writing quite a simple site and the most advanced topic I'm struggling with is a many-to-many relation between Projects and Resources that has an extra field called Priority. Any resource may be assigned to any number of projects with an integer priority.

    In the CMS, I would like to be able to assign resources on the project page, using a checkbox, like with ManyManyComplexTableField but also be able to put in the priority in an edit box. API reference notes that ManyManyComplexTableField is deprecated in favor of GridField and I also saw people recommending it here on forums when I searched but I have no idea on how to use it.

    Do you have a working example in one of your projects or maybe there is an existing addon with source code available to learn from? I would appreciate any tips on how to implement this functionality.

    Thanks in advance!

  • myak
    Avatar
    Community Member
    4 Posts

    Re: SS3: Many-to-many with extra field Link to this post

    Anyone? It's the only thing keeping me from choosing SS for this project. Any working solution would do, not necessarily based on GridField, I'm okay updating database directly, I just need a pointer in a right direction on how can I edit many-to-many extra fields.

  • DesignerX.com.au
    Avatar
    Community Member
    107 Posts

    Re: SS3: Many-to-many with extra field Link to this post

    Hi:
    For now , there does not seem to be enough info about GridField . Not enough tutorials anyway , I only recommend SS3 for smaller projects & try use SS2.4.7 for more complex ones as there are more tutorilas & info for SS2.4.x .

    Let us know if you find a solution.
    GL

  • myak
    Avatar
    Community Member
    4 Posts

    Re: SS3: Many-to-many with extra field Link to this post

    First of all, thanks for replying. I considered using 2.4 since it seems better supported and I don't think I wrote any code that would be incompatible. Do you know of any convenient solutions for extra fields? I found itemsetfield module (explanation for extra fields here) but maybe there's a better built-in solution?

    Cheers!

  • DesignerX.com.au
    Avatar
    Community Member
    107 Posts

    Re: SS3: Many-to-many with extra field Link to this post

    I had a look at the links you provided, they seem pretty good , I am not sure if there is a better solution ! .
    I would love to see the code & maybe try to get it working in SS3 ! Upload the Module here & I see what i can do:)
    Thanks

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: SS3: Many-to-many with extra field Link to this post

    I've just submitted a pull request for this to go into SS 3.1: https://github.com/silverstripe/sapphire/pull/939

  • myak
    Avatar
    Community Member
    4 Posts

    Re: SS3: Many-to-many with extra field Link to this post

    Looks good, can't wait to try it out. Thank you very much.

  • lekoala
    Avatar
    Community Member
    30 Posts

    Re: SS3: Many-to-many with extra field Link to this post

    I've had the same problem but since I'm not running the latest version, I'm not able to rely on Ingo solution.

    Meanwhile I tried to add a component that implements GridField_ColumnProvider that looks like this
    http://www.sspaste.com/paste/show/5100922035a71
    My main problem was that it's not possible (or not working?) to set a callback for the edit form for the detail view (which would enable me to add the extra fields to the detail form, which would be awesome). The callback is never called so... I've chosen a rather hacky way of doing things by simply allowing the user to click on the cell and enter a value. Then the value is updated through an ajax call.

    And I just have an action on my modeladmin that does this
    http://www.sspaste.com/paste/show/51009251eb64c

    so I realise this is not the standard way of doing things. But it would be super clean, I think, if it was possible to add a callback to the detail form to push the extra fields. This could be all automatically managed by model admin.

    Anyway, hope this helps someone

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