Accessing fields on many_many through relationship joined on a separate DataObject

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

Silverstripe Version: 4.5

Question:

I have set up the following:

class Trip extends DataObject
{
    private static $many_many = [
        "Clients" => [
            'through' => Booking::class,
            'from' => 'Trip',
            'to' => 'Client',
        ]
    ];
}
class Client extends Member
{
    private static $belongs_many_many = [
        'Trips' => Trip::class,
    ];
}
class Booking extends DataObject
{
    private static $db = [
        'Status' => 'Enum("unconfirmed,confirmed","unconfirmed")',
    ];

    private static $has_one = [
        'Trip' => Trip::class,
        'Client' => Client::class,
    ];
}

I’ve set up a Clients GridField (in the Trip Details form in CMS) with editable columns. I’d like to be able to add the Booking.Status field as an editable field, but haven’t figured out how to do so. Eg. a row in GridField would show Client.Name, Client.Email, Booking.Status (all fields except Booking.Status are already working fine).

Any help would be much appreciated!

1 Like

Ok, so I’ve managed to access the field info with Join.Status, but it won’t give me an editable field, eg. I’d expect the following to give me an editable dropdown field ???

$displayfields = [
		'Name' => [
			'title' => 'Name',
			'field' => ReadonlyField::class
        ],
		'Join.Status' => [
			'title' => 'Booking Status',
			'callback' => function($record, $column, $grid) {
				return DropdownField::create($column)
                    ->setSource(Booking::get()->DBObject('Status')->enumValues());
			}
		]
    ];

Bumping as I too am having trouble accessing ManyMany “through” fields. ManyMany_extraFields seem to work fine, but using ‘ManyMany[FieldName]’ doesn’t seem to work in the same way when the Field is managed by the through object (as above).
Any help would be much appreciated.