I have a query using a model to perform chunk operations on data taken from the "konfirmasi_pembayaran" table and perform a join with the "users" table to get the "nama" column. This query also uses orderBy to sort the data by the "user_nama" column (which is an alias for users.nama), but the expected sorting doesn't work well when using the chunk method.
Any help would be greatly appreciated.
The query as follow:
PHP Code:
$order = 0;
$model->select('konfirmasi_pembayaran.*, users.nama as user_nama')
->join('users', 'users.id = konfirmasi_pembayaran.user_id', 'left')
->where($where)
->orderBy('user_nama', 'asc')
->chunk(100, static function ($confirm) use (&$order, $model) {
$dataToUpdate = [
'order_id' => ($order++),
];
$model->update($confirm->id, $dataToUpdate);
});
Code:
"title": "CodeIgniter\\Database\\Exceptions\\DatabaseException",
"type": "CodeIgniter\\Database\\Exceptions\\DatabaseException",
"code": 500,
"message": "Unknown column 'user_nama' in 'order clause'",
without chunk the query is work fine:
PHP Code:
$dd = $model->select('konfirmasi_pembayaran.*, users.nama as user_nama')
->join('users', 'users.id = konfirmasi_pembayaran.user_id', 'left')
->where($where)
->orderBy('user_nama', 'desc')
->findAll();
dd($dd);
@xxxx[{::::::::::::::::::::::::::::::::>