Hi,
I have two tables: “tb_detalles” y “tb_palabras”, united by a third table, “detalles_palabras”. This last table contains two fields: “detalles_id” y “palabras_id”, which are the main key and which are related to the id of each of the respective “tb_detalles” y “tb_palabras”.
With the Datatable editor I can fill a column with multiple words for each record:
detalles_palabras (table)
detalles_id palabras_id (fields)
12 2
12 7
12 15
17 2
The summary code that I am using is the following:
$.fn.dataTable.Editor( {
fields: [
{
label: "Pal. Clave:",
name: "tb_palabra[].id",
type: "select2",
opts: {
"placeholder": "Select State",
"multiple": "multiple",
"allowClear": true
}
},
]
} );
$('#imagen_tbl').DataTable( {
columns: [
{ data: "tb_palabra", render: "[, ].palabra" },
]
} );
Data:
Editor::inst( $db, 'tb_detalle' )
->join(
Mjoin::inst( 'tb_palabra' )
->link( 'tb_detalle.id', 'palabra_detalle.detalle_id' )
->link( 'tb_palabra.id', 'palabra_detalle.palabra_id' )
->order( 'palabra asc' )
->fields(
Field::inst( 'id' )
->validator( Validate::required() )
->options( Options::inst()
->table( 'tb_palabra' )
->value( 'id' )
->label( 'palabra' )
),
Field::inst( 'palabra' )
)
->where( 'palabra_detalle.modo_id', 1 )
)
)
I want to add a new functionality and I need, that the table: “detalles_palabras” differentiate the data from other tables. For that I added a new field: “modo_id”
(Before)
detalles_palabras (table)
detalles_id palabras_id (fields)
12 2
12 7
12 15
17 2
(Now)
detalles_palabras (table)
detalles_id palabras_id modo_id (fields)
12 2 1
12 7 1
12 15 1
17 2 1
Data from a second Datatable
12 7 2
12 15 2
23 7 2
Data from a third Datatable
12 15 3
23 7 3
23 5 3
The question is: How can I do that when I add a word from each of the datatables, I automatically insert the data in the field mode_id, with the information of the corresponding table. With the example code, it would be a 1.
Thank you very much and happy year to all.