Skip to content

Commit

Permalink
增加自动写入(通过修改器定义)字段定义
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Sep 3, 2024
1 parent a04657e commit 302e683
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,15 @@ protected function insertData(string $sequence = null): bool
}
}

// 自动(使用修改器)写入字段
if (!empty($this->autoInsertFields)) {
foreach ($this->autoInsertFields as $field) {
if (!isset($this->data[$field])) {
$this->setAttr($field, null);
}
}
}

// 检查允许字段
$allowFields = $this->checkAllowFields();

Expand Down
7 changes: 7 additions & 0 deletions src/model/concern/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ trait Attribute
*/
private $withAttr = [];

/**
* 自动写入字段.
*
* @var array
*/
protected $autoInsertFields = [];

/**
* 获取模型对象的主键.
*
Expand Down

0 comments on commit 302e683

Please sign in to comment.