From f6f0c7854b3127fab1291de8aceef28d58d9e67e Mon Sep 17 00:00:00 2001 From: Billtec Date: Sun, 19 May 2024 21:44:47 +0800 Subject: [PATCH] fix: beforeUpdate & beforeSave is not working --- src/ActiveRecord.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index d94af60..35d1e2b 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -473,11 +473,13 @@ public function update(): ActiveRecord if (count($this->dirty) === 0) { return $this->resetQueryData(); } + + $this->processEvent([ 'beforeUpdate', 'beforeSave' ], [ $this ]); + foreach ($this->dirty as $field => $value) { $this->addCondition($field, '=', $value, ',', 'set'); } - $this->processEvent([ 'beforeUpdate', 'beforeSave' ], [ $this ]); $this->execute($this->eq($this->primaryKey, $this->{$this->primaryKey})->buildSql(['update', 'set', 'where']), $this->params); $this->processEvent([ 'afterUpdate', 'afterSave' ], [ $this ]);