I have a table structure similar to the example here: https://editor.datatables.net/manual/php/mjoin#Mjoin-class
My first table is "mechanics" with user_id and trade. The second table ("building_areas") uses building_area_id to identify the areas inside our buildings - it includes the building name and associated area name. The link table is "mechanic coverage" which is the mechanic id's and building_area id's. The mechanic id shows up several times in this table if the mechanic covers several areas.
I have successfully set up the mjoin and the table data is displaying as I had hoped. (The mechanic name, trade, and a concatenated list of the buildings and areas he/she covers). Picture attached.
My issue is that the field I would like to be able to edit (in the link table) is the mechanic id. When a mechanic calls in sick or has time off, a different mechanic covers those areas.
Editor::inst( $db, 'mechanic', 'user_id' )
->field(
Field::inst( 'mechanic.days' ),
Field::inst( 'mechanic.shift_start' ),
Field::inst( 'mechanic.shift_end' ), ...
)
->join(
Mjoin::inst('building_areas')
->link('mechanic.user_id', 'mech_coverage.today_mechanic')
->link('building_areas.area_id', 'mech_coverage.building_area_id')
->fields(
Field::inst( 'area_id' )
->validator( 'Validate::required' )
->options( Options::inst()
->table( 'building_areas' )
->value( 'area_id' )
->label( array('building_name', 'area_name') )
),
Field::inst('building_name'),
Field::inst('area_name')
->setFormatter( 'Format::ifEmpty', null )
)
)
I would like to edit mech_coverage.today_mechanic - not the building areas but I haven't been able to figure out how to do it. Is there something simple I'm missing or should I have approached this a completely different way?
A couple of key features I'm hoping not to lose: mechanic shows up only once in display, building_areas are a concatenated list in one column.
Thank you for any help.