From aab3858b13d85553b2c7de9ee474d26cdd10576b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 24 Jun 2024 21:57:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E5=A2=9E=E5=8A=A0autoInc?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E7=94=A8=E4=BA=8E=E8=AE=BE=E7=BD=AE=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=A1=A8=E8=87=AA=E5=A2=9E=E4=B8=BB=E9=94=AE=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=88=96true?= =?UTF-8?q?=EF=BC=88=E8=87=AA=E5=8A=A8=E8=8E=B7=E5=8F=96=E4=B8=BB=E9=94=AE?= =?UTF-8?q?=E5=80=BC=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Model.php | 4 ++++ src/model/concern/Attribute.php | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/Model.php b/src/Model.php index 714b341b..6fb59728 100644 --- a/src/Model.php +++ b/src/Model.php @@ -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); } diff --git a/src/model/concern/Attribute.php b/src/model/concern/Attribute.php index 3fb8a52b..4625fd11 100644 --- a/src/model/concern/Attribute.php +++ b/src/model/concern/Attribute.php @@ -33,6 +33,13 @@ trait Attribute */ protected $pk = 'id'; + /** + * 数据表主键自增. + * + * @var bool|null|string + */ + protected $autoInc; + /** * 数据表字段信息 留空则自动获取. *