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.

Customising the CMS

SS3: Many-to-many with extra field


Reply

8 Posts   1014 Views

Avatar
myak

27 July 2012 at 9:34pm Community Member, 4 Posts

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!

Avatar
myak

7 August 2012 at 5:18am Community Member, 4 Posts

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.

Avatar
DesignerX.com.au

9 August 2012 at 5:15am Community Member, 107 Posts

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

Avatar
myak

9 August 2012 at 5:20am Community Member, 4 Posts

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 [url=https://github.com/ajshort/silverstripe-itemsetfield]itemsetfield[/url] module (explanation for extra fields [url=https://groups.google.com/forum/?fromgroups#!topic/silverstripe-dev/kJB7BuChb8A%5B1-25%5D]here[/url]) but maybe there's a better built-in solution?

Cheers!

Avatar
DesignerX.com.au

9 August 2012 at 5:30am Community Member, 107 Posts

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

Avatar
Ingo

8 November 2012 at 1:53pm Forum Moderator, 801 Posts

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

Avatar
myak

8 November 2012 at 1:58pm Community Member, 4 Posts

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

Avatar
lekoala

24 January 2013 at 2:48pm (Last edited: 24 January 2013 2:49pm), Community Member, 30 Posts

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 :-)