Skip to content

Commit

Permalink
模型增加autoInc属性用于设置数据表自增主键 支持字符串或true(自动获取主键值)
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Jun 24, 2024
1 parent d65cb89 commit aab3858
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ public function db($scope = []): Query
->name($this->name . $this->suffix)
->pk($this->pk);

if (!empty($this->autoInc)) {
$query->autoinc(is_string($this->autoInc) ? $this->autoInc : $this->pk);
}

if (!empty($this->table)) {
$query->table($this->table . $this->suffix);
}
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 @@ -33,6 +33,13 @@ trait Attribute
*/
protected $pk = 'id';

/**
* 数据表主键自增.
*
* @var bool|null|string
*/
protected $autoInc;

/**
* 数据表字段信息 留空则自动获取.
*
Expand Down

0 comments on commit aab3858

Please sign in to comment.