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.');
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();