From 20ee6f6b0c00aedf37bae86b6df3b149822957ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 25 Feb 2021 18:26:15 +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 | 19 ++----------------- Database/Base/BaseActiveRecord.php | 4 ++-- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/Database/ActiveRecord.php b/Database/ActiveRecord.php index 0a2b6624..4c8485e8 100644 --- a/Database/ActiveRecord.php +++ b/Database/ActiveRecord.php @@ -177,28 +177,13 @@ class ActiveRecord extends BaseActiveRecord return $this->save($fields); } - /** - * @param array $params - * @param array $condition - * @return bool|static - * @throws Exception - */ - public static function insertOrUpdate(array $params, array $condition): bool|static - { - $first = static::findOrCreate($condition, $params); - $first->attributes = $params; - if (!$first->save()) { - return false; - } - return $first; - } /** * @param array $data * @return bool * @throws Exception */ - public static function batchInsert(array $data): bool + public static function inserts(array $data): bool { /** @var static $class */ $class = Snowflake::createObject(static::className()); @@ -242,7 +227,7 @@ class ActiveRecord extends BaseActiveRecord * @return bool * @throws Exception */ - public static function batchUpdate($condition, $attributes = []): bool + public static function updateAll(mixed $condition, $attributes = []): bool { $condition = static::find()->where($condition); return $condition->batchUpdate($attributes); diff --git a/Database/Base/BaseActiveRecord.php b/Database/Base/BaseActiveRecord.php index 1dcb3068..201c2882 100644 --- a/Database/Base/BaseActiveRecord.php +++ b/Database/Base/BaseActiveRecord.php @@ -457,7 +457,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess * @return $this|bool * @throws Exception */ - private function update($fields, $condition, $param): bool|static + private function updateInternal($fields, $condition, $param): bool|static { if (empty($param)) { return true; @@ -509,7 +509,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess [$change, $condition, $fields] = $this->filtration_and_separation(); if (!$this->isNewExample) { - return $this->update($fields, $condition, $change); + return $this->updateInternal($fields, $condition, $change); } return $this->insert($change, $fields); }