From 50f2db7a2dd600b4b835ca20027ecff5f1ebebb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Tue, 9 Nov 2021 16:40:32 +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 --- src/Base/Model.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Base/Model.php b/src/Base/Model.php index 5a2d75b..a898b43 100644 --- a/src/Base/Model.php +++ b/src/Base/Model.php @@ -13,12 +13,10 @@ defined('SAVE_FAIL') or define('SAVE_FAIL', 3227); defined('FIND_OR_CREATE_MESSAGE') or define('FIND_OR_CREATE_MESSAGE', 'Create a new model, but the data cannot be empty.'); -use Annotation\Inject; use ArrayAccess; use Closure; use Database\ActiveQuery; use Database\Connection; -use Database\HasCount; use Database\HasMany; use Database\HasOne; use Database\ModelInterface; @@ -98,12 +96,6 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T protected string $connection = 'db'; - /** - * @var array - */ - protected array $rules = []; - - /** * @var array */ @@ -119,6 +111,15 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T } + /** + * @return array + */ + public function rules(): array + { + return []; + } + + /** * @param string $name * @param mixed $value @@ -611,7 +612,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T if (!is_null($data)) { $this->_attributes = merge($this->_attributes, $data); } - if (!$this->validator($this->rules) || !$this->beforeSave($this)) { + if (!$this->validator($this->rules()) || !$this->beforeSave($this)) { return false; } [$change, $condition, $fields] = $this->separation();