Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: afterUpdate event return array instead of key value #3450

Closed
oleg1540 opened this issue Aug 5, 2020 · 2 comments
Closed

Bug: afterUpdate event return array instead of key value #3450

oleg1540 opened this issue Aug 5, 2020 · 2 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@oleg1540
Copy link
Contributor

oleg1540 commented 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:

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]
@oleg1540 oleg1540 added the bug Verified issues on the current code behavior or pull requests that will fix them label Aug 5, 2020
@michalsn
Copy link
Member

michalsn commented Aug 6, 2020

I guess that the user guide has to be updated. It's because update() method accepts also an array of ids.

PR would be appreciated :)

@oleg1540
Copy link
Contributor Author

oleg1540 commented Aug 6, 2020

Ok, I'll make PR with changes in docs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

2 participants