You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I tried to use model events - afterInsert and afterUpdate. protected $afterInsert = ['someFunction']; protected $afterUpdate = ['someFunction'];
According the docs afterInsert and afterUpdate must return id:
id = the primary key of the new row, or 0 on failure.
id = the primary key of the row being updated.
But afterUpdate return id as array.
I opened system/Model.php and found out there this code: if (is_numeric($id) || is_string($id)) { $id = [$id]; }
... $eventData = [ 'id' => $id, 'data' => $eventData['data'], 'result' => $result, ];
In this regard, the question - is it bug in event data or inaccuracy in the docs?
CodeIgniter 4 version
4.0.3.
Expected behavior, and steps to reproduce if appropriate
I expected to get primary key value in someFunction instead of array. protected function someFunction($data) { var_dump($data['id']); // didn't expect array }
Another way - make notice about it in docs.
Context
OS: [Windows 7]
Web server [Apache 2.4]
PHP version [7.4.5]
The text was updated successfully, but these errors were encountered:
oleg1540
added
the
bug
Verified issues on the current code behavior or pull requests that will fix them
label
Aug 5, 2020
Describe the bug
I tried to use model events - afterInsert and afterUpdate.
protected $afterInsert = ['someFunction'];
protected $afterUpdate = ['someFunction'];
According the docs afterInsert and afterUpdate must return id:
But afterUpdate return id as array.
I opened system/Model.php and found out there this code:
if (is_numeric($id) || is_string($id)) { $id = [$id]; }
...
$eventData = [ 'id' => $id, 'data' => $eventData['data'], 'result' => $result, ];
In this regard, the question - is it bug in event data or inaccuracy in the docs?
CodeIgniter 4 version
4.0.3.
Expected behavior, and steps to reproduce if appropriate
I expected to get primary key value in someFunction instead of array.
protected function someFunction($data) { var_dump($data['id']); // didn't expect array }
Another way - make notice about it in docs.
Context
The text was updated successfully, but these errors were encountered: