This Options Instance
Field::inst( 'report.report_type_id' )->validator( 'Validate::notEmpty', array('message' => $msg[0]) )
->options( Options::inst()
->table('report_type')
->value('id')
->label('label')
->order('number asc')
//where clause MUST be a closure function in Options!!!
->where( function($q) {
$q ->where( 'user_id', $_SESSION['id'] );
} )
),
generates this SQL Statement:
...
SELECT DISTINCT `id` as 'id', `label` as 'label' FROM `report_type` WHERE (`user_id` = 64 ) ORDER BY `number` asc
This causes an error in some DBMS's because the ORDER BY field "number" is not in the SELECT field list. In my case it works fine locally with XAMPP and MariaDB but does not work on the server side with MySQL which is particularly annoying because you think everyhting is fine when testing locally. For the time being I found this work around.
Field::inst( 'report.report_type_id' )->validator( 'Validate::notEmpty', array('message' => $msg[0]) )
->options( Options::inst()
->table('report_type')
->value('id')
->label( array('label', 'number') ) //we need to get number into the field list otherwise SQL error with the server MySQL-Version.
->render( function ( $row ) { return $row['label']; } )
->order('number asc')
//where clause MUST be a closure function in Options!!!
->where( function($q) {
$q ->where( 'user_id', $_SESSION['id'] );
} )
),
This forces Editor to put "number" in the SELECT field list even though I don't need the field returned to the client.
@Allan: could you make a change in Editor that it always puts all ORDER BY fields in the SELECT field list please. This would be very helpful. Many thanks.