From 24eccc811ec37f76eedd1bc52603c125a2935719 Mon Sep 17 00:00:00 2001 From: MGatner Date: Tue, 15 Oct 2019 14:39:12 -0400 Subject: [PATCH] Change after methods to return actual data --- system/Model.php | 15 +++------------ user_guide_src/source/models/model.rst | 5 +++-- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/system/Model.php b/system/Model.php index d389ca92d911..701484a8233d 100644 --- a/system/Model.php +++ b/system/Model.php @@ -687,11 +687,6 @@ public function insert($data = null, bool $returnID = true) } } - // Save the original data so it can be passed to - // any Model Event callbacks and not stripped - // by doProtectFields - $originalData = $data; - // Must be called first so we don't // strip out created_at values. $data = $this->doProtectFields($data); @@ -722,7 +717,8 @@ public function insert($data = null, bool $returnID = true) $this->insertID = $this->db->insertID(); } - $this->trigger('afterInsert', ['data' => $originalData, 'result' => $result]); + // Trigger afterInsert events with the inserted data and new ID + $this->trigger('afterInsert', ['id' => $this->insertID, 'data' => $data, 'result' => $result]); // If insertion failed, get out of here if (! $result) @@ -821,11 +817,6 @@ public function update($id = null, $data = null): bool } } - // Save the original data so it can be passed to - // any Model Event callbacks and not stripped - // by doProtectFields - $originalData = $data; - // Must be called first so we don't // strip out updated_at values. $data = $this->doProtectFields($data); @@ -849,7 +840,7 @@ public function update($id = null, $data = null): bool ->set($data['data'], '', $escape) ->update(); - $this->trigger('afterUpdate', ['id' => $id, 'data' => $originalData, 'result' => $result]); + $this->trigger('afterUpdate', ['id' => $id, 'data' => $data, 'result' => $result]); return $result; } diff --git a/user_guide_src/source/models/model.rst b/user_guide_src/source/models/model.rst index 8159a5c94c53..28d59d58e4d6 100644 --- a/user_guide_src/source/models/model.rst +++ b/user_guide_src/source/models/model.rst @@ -715,13 +715,14 @@ Event $data contents ================ ========================================================================================================= beforeInsert **data** = the key/value pairs that are being inserted. If an object or Entity class is passed to the insert method, it is first converted to an array. -afterInsert **data** = the original key/value pairs being inserted. +afterInsert **id** = the primary key of the new row, or 0 on failure. + **data** = the key/value pairs being inserted. **result** = the results of the insert() method used through the Query Builder. beforeUpdate **id** = the primary key of the row being updated. **data** = the key/value pairs that are being inserted. If an object or Entity class is passed to the insert method, it is first converted to an array. afterUpdate **id** = the primary key of the row being updated. - **data** = the original key/value pairs being updated. + **data** = the key/value pairs being updated. **result** = the results of the update() method used through the Query Builder. afterFind Varies by find* method. See the following: - find() **id** = the primary key of the row being searched for.