![]() |
I am implementing a database writes log for my app through the Codeigniter 4 Model events ($afterInsert, $afterUpdate and $afterDelete). Each log entry (the log resides in a separate database table) should include info on (1) the database table, (2) the row inserted/updated/deleted, (3) action type and (4) the serialized content of update/insert.
So, for example, after each db update a callback function log_db_update($data) is invoked, which is supplied by the $data array, that normally should include, to quote the manual: Quote:id = the array of primary keys of the rows being updated.Now, the problem is, I do not always get the id for the hook when I update (or when I delete). If the update code finds the data to update by id, let's say: PHP Code: $watchesModel->update($id, $data); PHP Code: $watchesModel->where('date', $date)->set($data)->update(); I see I can only do one thing: rewrite the update statements into find & update statements, like this: PHP Code: $entry = $watchesModel->where('date', $date)->first(); So, I have two questions: 1. Is there a better way to get what I want? 2. Is this behaviour of hooks something that I should report as a bug or "needs improvement" thing for the team developing Codeigniter? Or would changing this behaviour be too much to ask for (and if so, why)? Donatas
==
Donatas G. |
Messages In This Thread |
logging db actions via model events and id problem - by dgvirtual - 01-12-2022, 12:55 PM
RE: logging db actions via model events and id problem - by kenjis - 01-12-2022, 07:41 PM
RE: logging db actions via model events and id problem - by dgvirtual - 01-13-2022, 03:36 AM
RE: logging db actions via model events and id problem - by iRedds - 01-13-2022, 11:59 AM
RE: logging db actions via model events and id problem - by MGatner - 01-17-2022, 06:58 AM
RE: logging db actions via model events and id problem - by dgvirtual - 01-19-2022, 12:20 PM
|