Working with many_many_through relationships

Silverstripe Version: 4.5.1

Question:

I can’t get ModelAdmin to work with Many_Many_Through relationships. I’ve set up the example given here https://docs.silverstripe.org/en/4/developer_guides/model/relations/#many-many-through-relationship-joined-on-a-separate-dataobject

My ModelAdmin is set up as per https://docs.silverstripe.org/en/4/developer_guides/forms/field_types/gridfield/#many-many-extrafields

I’ve also tried specifying the ItemEditFormCallback as per SS4: edit many_many_extraFields in a GridField detail form - SilverStrip.es

The problem is the additional fields show, but do not load or save data.

Here’s a gist Teamp.php · GitHub

1 Like

What happens if you change (this line) ManyMany[Ranking] to Supporters[Ranking]?

I haven’t tried to do this before but I’m guessing the docs have an error and that the example code should have new TextField('Teams[Position]', 'Current Position') instead of new TextField('ManyMany[Position]', 'Current Position').

Hi Jono,

Yeah I’ve tried that as well - no difference.

I’ve found the problem, but not the solution (yet). The issue is the GridFieldDetailForm_ItemRequest only loads from the ManyMany array if the list is an instance of ManyManyList

ManyManyThroughList extends RelationList directly, so it’s not the correct instance.

Interesting. If you change that to $list instanceof ManyManyList || $list instanceof ManyManyThroughList does it work? Probably not that simple but you never know. There are likely other similar instances like that which might need updating, here’s another.

No, it doesn’t work because the ManyManyThroughList doesn’t have the getExtraData function.
I’ve raised a GitHub issue for it Gridfield does not load or save data from many many through relationships · Issue #9428 · silverstripe/silverstripe-framework · GitHub