Model类增加getPk方法用于获取主键

This commit is contained in:
thinkphp
2016-04-09 15:13:25 +08:00
parent f68f27e245
commit e60f497bd6

View File

@@ -316,11 +316,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
*/ */
public function getPk($tableName = '') public function getPk($tableName = '')
{ {
if ($this->pk) { if (!$this->pk) {
return $this->pk; $this->pk = self::db()->getTableInfo($tableName, 'pk');
} else {
return self::db()->getTableInfo($tableName, 'pk');
} }
return $this->pk;
} }
/** /**