From 12fc7d470f9abba9605b2493739260a9c594bd04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 10 Sep 2020 16:48:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/ActiveRecord.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Database/ActiveRecord.php b/Database/ActiveRecord.php index 80cfc761..33fa38a5 100644 --- a/Database/ActiveRecord.php +++ b/Database/ActiveRecord.php @@ -193,16 +193,8 @@ class ActiveRecord extends BaseActiveRecord if (empty($condition)) { $condition = $params; } - $first = static::find()->where($condition)->first(); - if (empty($first)) { - $model = new static(); - $model->attributes = $params; - return $model->save(); - } - - foreach ($params as $key => $param) { - $first->{$key} = $param; - } + $first = static::findOrCreate($condition, $params); + $first->attributes = $params; if (!$first->save()) { return false; }