I have 2 tables. One (otc_transport
) stores useful info. The second ('otc_transport_ord')is a link table that stores which transport is associated with a particular shipment order. So the link table has 2 columns: id_order
and id_transport
.
In my table, I need to display the list of transports, to add, edit and delete. As the table is in the current order page, the id_order
is set directly.
I tried first the version with simple join.
I can add rows, I can edit rows, I can NOT delete a row.
Error when I confirm deleting the row is:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'otc_transport.id_transport' in 'where clause'
Here is the code:
Editor::inst( $db, 'otc_transport', 'id_transport' )
->fields(
Field::inst( 'otc_transport.id_transport'),
Field::inst( 'otc_transport_ord.id_order' ) ->setValue( $_GET['id_order']),
// useful fields:
Field::inst( 'otc_transport.id_type' ),
Field::inst( 'otc_transport.name' )->validator( 'Validate::notEmpty' ),
// more fields....
)
->leftJoin( 'otc_transport_ord', 'otc_transport_ord.id_transport', '=', 'otc_transport.id_transport' )
->where( 'otc_transport_ord.id_order', $_GET['id_order'] )
->process($_POST)
->json();
then I tried the Mjoin version for direct link as described in One-to-many joins documentation, but i get the warning:
DataTables warning: table id=tabel_transport - Table selected fields (i.e. '{table}.{column}') in
Join
must be read only. Useset(false)
for the field to disable writing
Editor::inst( $db, 'otc_transport', 'id_transport' )
->fields(
Field::inst( 'otc_transport.id_transport' ),
// useful fields:
Field::inst( 'otc_transport.id_type' ),
Field::inst( 'otc_transport.name' )->validator( 'Validate::notEmpty' ),
// more fields....
)
->join(
Mjoin::inst( 'otc_transport_ord.id_transport','otc_transport.id_transport' )
->fields(
Field::inst( 'otc_transport_ord.id_order' ) ->setValue( $_GET['id_order'])
)
)
->process($_POST)
->json();
so..... what am I missing? What do I do wrong?
Why, if I can create a transport and the link tables is updated and all works perfect, I can not delete it? It makes no sense to me.
Other info:
1. Editor version is 1.6
2. I have no other bugs, all info are sent correct. Proof is that create and edit works ok.
3. if I remember well the delete was also working when I first created the table. We discover the bug now, on final testing. Maybe I did not had 1.6 back then? Can not tell for sure.
4. Debug with file_put_contents returns a wrong SQL: sql DELETE FROM `otc_transport` WHERE (`otc_transport`.`id_transport` = :where_1 AND `otc_transport_ord`.`id_ord` = :where_2 )