This commit is contained in:
2021-11-09 16:40:32 +08:00
parent a538c39837
commit 50f2db7a2d
+10 -9
View File
@@ -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.'); 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 ArrayAccess;
use Closure; use Closure;
use Database\ActiveQuery; use Database\ActiveQuery;
use Database\Connection; use Database\Connection;
use Database\HasCount;
use Database\HasMany; use Database\HasMany;
use Database\HasOne; use Database\HasOne;
use Database\ModelInterface; use Database\ModelInterface;
@@ -98,12 +96,6 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
protected string $connection = 'db'; protected string $connection = 'db';
/**
* @var array
*/
protected array $rules = [];
/** /**
* @var array * @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 string $name
* @param mixed $value * @param mixed $value
@@ -611,7 +612,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
if (!is_null($data)) { if (!is_null($data)) {
$this->_attributes = merge($this->_attributes, $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; return false;
} }
[$change, $condition, $fields] = $this->separation(); [$change, $condition, $fields] = $this->separation();