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

SS3: Many-to-many with extra field


Go to End


8 Posts   2451 Views

Avatar
myak

Community Member, 4 Posts

27 July 2012 at 9:34pm

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

Community Member, 4 Posts

7 August 2012 at 5:18am

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

Community Member, 107 Posts

9 August 2012 at 5:15am

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

Community Member, 4 Posts

9 August 2012 at 5:20am

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!

Avatar
DesignerX.com.au

Community Member, 107 Posts

9 August 2012 at 5:30am

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

Forum Moderator, 801 Posts

8 November 2012 at 1:53pm

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

Avatar
myak

Community Member, 4 Posts

8 November 2012 at 1:58pm

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

Avatar
lekoala

Community Member, 31 Posts

24 January 2013 at 2:48pm

Edited: 24/01/2013 2:49pm

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