Skip to content

Commit 1637860

Browse files
committed
Model增加getAutoInc方法 改进getPk方法判断
1 parent ac7c41b commit 1637860

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/model/concern/Attribute.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,17 @@ private function initializeData(array | object $data, bool $fromSave = false)
101101
*/
102102
public function getPk()
103103
{
104-
return $this->getOption('pk');
104+
return $this->getOption('pk', 'id');
105+
}
106+
107+
/**
108+
* 获取自增键名.
109+
*
110+
* @return string
111+
*/
112+
public function getAutoInc()
113+
{
114+
return $this->getOption('autoInc', $this->getPk());
105115
}
106116

107117
/**

src/model/concern/DbConnect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getQuery()
4242

4343
return $db->schema($this->getOption('schema'))
4444
->pk($this->getPk())
45-
->autoInc($this->getOption('autoInc'))
45+
->autoInc($this->getAutoInc())
4646
->suffix($this->getOption('suffix'))
4747
->setKey($this->getKey())
4848
->replace($this->getOption('replace', false))

0 commit comments

Comments
 (0)