Mjoin issue - Field not included in editor field list
Mjoin issue - Field not included in editor field list
peterbrowne
Posts: 314Questions: 54Answers: 0
in Editor
This is the error:
{"sError":"Join was performed on the field 'unit_outcome_pk' which was not included in the Editor field list. The join field must be included as a regular field in the Editor instance."}
Code for editor:
<div class='table_container'>
<table id='assessment_table' class='display' style="width:100%">
<thead>
<tr>
<th>Assessment</th>
<th>Unit</th>
<th>Weighting</th>
<th>Assessment Type</th>
<th>Unit Outcome</th>
<th>Modified</th>
<th>Modified By</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div id="assessment_form">
<editor-field name="assessment.assessment"></editor-field>
<editor-field name="unit[].unit_pk"></editor-field>
<editor-field name="assessment.weighting"></editor-field>
<editor-field name="assessment_type[].assessment_type_pk"></editor-field>
<editor-field name="unit_outcome[].unit_outcome_pk"></editor-field>
</div>
var editor = new $.fn.dataTable.Editor( {
ajax: "program_data/assessment_data.php",
table: "#assessment_table",
"autoWidth": true,
template: '#assessment_form',
fields: [ {
label: "Assessment:",
name: "assessment.assessment",
type: "ckeditor"
}, {
label: "Unit:",
name: "unit[].unit_pk",
type: "select",
placeholder: 'No selection',
placeholderDisabled: false,
placeholderValue: 0,
multiple: true
}, {
label: "Weighting:",
name: "assessment.weighting"
}, {
label: "Assessment type:",
name: "assessment_type[].assessment_type_pk",
type: "select",
placeholder: 'No selection',
placeholderDisabled: false,
placeholderValue: 0,
multiple: true
}, {
label: "Unit Outcome:",
name: "unit_outcome[].unit_outcome_pk",
type: "select",
placeholder: 'No selection',
placeholderDisabled: false,
placeholderValue: 0,
multiple: true
}]
} );
var table = $( '#assessment_table' ).DataTable( {
responsive: true,
ajax: "program_data/assessment_data.php",
dom: "Blfrtip",
columns: [ {
data: "assessment.assessment"
}, {
data: "unit",
render: "[, ].unit_name"
}, {
data: "assessment.weighting"
}, {
data: "assessment_type",
render: "[, ].assessment_type"
}, {
data: "unit_outcome",
render: "[, ].unit_outcome"
}, {
data: "assessment.modified"
}, {
data: "assessment.modified_by"
} ],
select: {
style: 'os',
selector: 'td:first-child'
},
buttons: [ ]
} );
Data code:
include( "../../../datatables/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,
DataTables\Editor\ValidateOptions;
Editor::inst( $db_cm_md, 'assessment', 'assessment_pk' )
->field(
Field::inst( 'assessment.assessment' ),
Field::inst( 'assessment.weighting' ),
Field::inst( 'assessment.modified' ),
Field::inst( 'assessment.modified_by' )->setValue( $user )
)
->join(
Mjoin::inst( 'unit' )
->link( 'assessment.assessment_pk', 'unit_assessment_lookup.assessment_fk' )
->link( 'unit.unit_pk', 'unit_assessment_lookup.unit_fk' )
->order( 'unit.unit_name asc' )
->fields(
Field::inst( 'unit_pk' )
->options( Options::inst()
->table( 'unit' )
->value( 'unit_pk' )
->label( 'unit_name' )
),
Field::inst( 'unit_name' )
)
)
->join(
Mjoin::inst( 'assessment_type' )
->link( 'assessment.assessment_pk', 'assessment_assessment_type_lookup.assessment_fk' )
->link( 'assessment_type.assessment_type_pk', 'assessment_assessment_type_lookup.assessment_type_fk' )
->order( 'assessment_type.assessment_type asc' )
->fields(
Field::inst( 'assessment_type_pk' )
->options( Options::inst()
->table( 'assessment_type' )
->value( 'assessment_type_pk' )
->label( 'assessment_type' )
),
Field::inst( 'assessment_type' )
)
)
->join(
Mjoin::inst( 'unit_outcome' )
->link( 'unit_outcome.unit_outcome_pk', 'unit_outcome_assessment_lookup.unit_outcome_fk' )
->link( 'assessment.assessment_pk', 'unit_outcome_assessment_lookup.assessment_fk' )
->order( 'unit_outcome.unit_outcome asc' )
->fields(
Field::inst( 'unit_outcome_pk' )
->options( Options::inst()
->table( 'unit_outcome' )
->value( 'unit_outcome_pk' )
->label( 'unit_outcome' )
),
Field::inst( 'unit_outcome' )
)
)
->process($_POST)
->json();
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
OK, fixed that issue by swapping:
to
But now I get:
"A system error has occured."
The error message is:
Notice: Array to string conversion in /var/www/html/curriculum_mapper/datatables/lib/Database/Driver/MysqlQuery.php on line 97 {"data":[{"DT_RowId":"row_1","assessment":{"assessment":"
IMS1 Written Examination MCQ - Wk 5<\/p>","weighting":"10%","modified":"2020-03-06 14:32:24","modified_by":"00082563","unit_fk":"0"},"unit":{"unit_name":null},"assessment_type":[{"assessment_type_pk":"1","assessment_type":"Written Examination - MCQ"}],"unit_outcome":[{"unit_outcome_pk":"1","unit_outcome":"
Display professional behaviour in the educational and clinical settings and outline some challenges to professionalism<\/p>"},{"unit_outcome_pk":"39","unit_outcome":"
Display professional, concise and accurate oral, written and electronic biomedical communication skills<\/p>"}]}]}
Can I please get an answer on this?
Hi,
Sorry I was unable to get back to you yesterday, I was wrapped up with other things. Unfortunately today has ram away from me as well, but I'll post back having considered the issue properly tomorrow.
Allan
The one thing in the error message tat looks odd to me is that
unit
is not an array, but it should be based on the configuration.Could you change:
to be:
and then show me the JSON return from the server (it might still include the error message).
Also, I presume that this error message is appearing on create or edit. Not on the initial population of the table?
Thanks,
Allan
Hi Allan
Thanks for looking into this. Yes, the error only happens on create and edit. I suspect that something might not be escaped properly.
Here is what is returned:
Note that the record is created in the assessment table, but the assessment.unit_fk is not populated with the unit.unit_pk.
The records are created in the two lookup tables correctly.
The tables structure:
OK, I think I found the the problem, but not sure what exactly is causing the error:
If I change:
to:
I don't get any errors and the assessment.unit_fk is populated correctly from unit.unit_pk and everything else is at it should be in the db.
I actually don't want multiple selections anyway from the unit select...
Ah I see - so on the
assessment
table there is a single unique reference to theunit
table throughunit_fk
. In that case aleftJoin
would be the way to do with with aselect
which is, as you say, not a multiple selection (single by default).Allan