A field already exists with this name with multiple mjoins
A field already exists with this name with multiple mjoins
mattdykstra
Posts: 3Questions: 2Answers: 0
I have a table with multiple mjoins which results in the same field inst name. I get an error "uncaught exception: Error adding field 'process[].process_id'. A field already exists with this name" I cannot figure out a way to give it another name. Can anyone help?
<?php
session_start();
/*
* Editor server script for DB table products
* Created by http://editor.datatables.net/generator
*/
// DataTables PHP library and database connection
include( "lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'filters', 'filter_id' )
->fields(
Field::inst( 'filters.entity_id' )
->setValue( $_SESSION['selected_entity'] ),
Field::inst( 'filters.filter_name' )
->validator( 'Validate::notEmpty' )
)
->where( 'entity_id', $_SESSION['selected_entity'] )
->join(
Mjoin::inst( 'tags' )
->link( 'filters.filter_id', 'filter_tags.filter_id' )
->link( 'tags.tag_id', 'filter_tags.tag_id' )
->fields(
Field::inst( 'tag_id' )
->validator( 'Validate::required' )
->options( Options::inst()
->table( 'tags' )
->value( 'tag_id' )
->label( 'tag' )
->where( function ( $q ) {
$q->where( 'entity_id', $_SESSION['selected_entity']);
})
),
Field::inst( 'tag' )
)
)
->join(
Mjoin::inst( 'process' )
->link( 'filters.filter_id', 'filter_process.filter_id' )
->link( 'process.process_id', 'filter_process.process_id' )
->fields(
Field::inst( 'process_id' )
->validator( 'Validate::required' )
->options( Options::inst()
->table( 'process' )
->value( 'process_id' )
->label( 'process_name' )
->where( function ( $q ) {
$q->where( 'entity_id', $_SESSION['selected_entity']);
})
),
Field::inst( 'process_name' )
)
)
->join(
Mjoin::inst( 'process' )
->link( 'filters.filter_id', 'filter_process_buttons.filter_id' )
->link( 'process.process_id', 'filter_process_buttons.process_id' )
->fields(
Field::inst( 'process_id' )
->validator( 'Validate::required' )
->options( Options::inst()
->table( 'process' )
->value( 'process_id' )
->label( 'process_name' )
->where( function ( $q ) {
$q->where( 'entity_id', $_SESSION['selected_entity']);
})
),
Field::inst( 'process_name' )
)
)
->process( $_POST )
->json();
(function($){
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: 'assets/DataTablesEditor/php/table.filters.php',
table: '#filters',
fields: [
{
"label": "Filter Name:",
"name": "filters.filter_name"
},
{
"label": "Tags:",
"name": "tags[].tag_id",
"type": "select2",
"opts": {
"placeholder": "Select Tags",
"multiple": true
}
},
{
"label": "Process Filter:",
"name": "process[].process_id",
"type": "select2",
"opts": {
"placeholder": "Select Status",
"multiple": true
}
},
{
"label": "Process Buttons:",
"name": "process[].process_id",
"type": "select2",
"opts": {
"placeholder": "Select Status",
"multiple": true
}
}
]
} );
var table = $('#filters').DataTable( {
dom: 'Bfrtip',
ajax: 'assets/DataTablesEditor/php/table.filters.php',
columns: [
{
"data": "filters.filter_name"
},
{
"data": "tags", "render": "[, ].tag"
},
{
"data": "process", "render": "[, ].process_name"
},
{
"data": "process", "render": "[, ].process_name"
}
],
select: true,
lengthChange: false,
buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
]
} );
} );
}(jQuery));
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Yes - this is happening as
Mjoin::inst( 'process' )
is present twice.There is a workaround for this in the PHP libraries at the moment using the
Mjoin->name()
method which can be used to rename one, or both of them (make sure you update the client-side code to reflect the changed name as well!).Allan