mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
改进Model类的getPk方法
This commit is contained in:
@@ -255,15 +255,18 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前模型对象的主键
|
* 获取模型对象的主键
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $table 数据表名
|
* @param string $name 模型名
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getPk($table = '')
|
public function getPk($name = '')
|
||||||
{
|
{
|
||||||
if (empty($this->pk)) {
|
if (!empty($name)) {
|
||||||
$this->pk = $this->db()->getTableInfo($table, 'pk');
|
$table = $this->db()->getTable($name);
|
||||||
|
return $this->db()->getPk($table);
|
||||||
|
} elseif (empty($this->pk)) {
|
||||||
|
$this->pk = $this->db()->getPk();
|
||||||
}
|
}
|
||||||
return $this->pk;
|
return $this->pk;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -667,9 +667,9 @@ class Query
|
|||||||
$alias = $join;
|
$alias = $join;
|
||||||
}
|
}
|
||||||
$table = !empty($table) ? $table : $this->getTable($join);
|
$table = !empty($table) ? $table : $this->getTable($join);
|
||||||
if(true === $field){
|
if (true === $field) {
|
||||||
$fields = $alias . '.*';
|
$fields = $alias . '.*';
|
||||||
}else{
|
} else {
|
||||||
if (is_string($field)) {
|
if (is_string($field)) {
|
||||||
$field = explode(',', $field);
|
$field = explode(',', $field);
|
||||||
}
|
}
|
||||||
@@ -1196,7 +1196,7 @@ class Query
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前模型对象的主键
|
* 获取当前数据表的主键
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $table 数据表名
|
* @param string $table 数据表名
|
||||||
* @return string|array
|
* @return string|array
|
||||||
|
|||||||
Reference in New Issue
Block a user