mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
模型类的field属性定义简化 取消Query类的allowField和setFieldType方法及相关属性 交给数据表字段缓存
This commit is contained in:
@@ -156,24 +156,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
$query->name($this->name);
|
||||
}
|
||||
|
||||
if (!empty($this->field)) {
|
||||
if (true === $this->field) {
|
||||
$type = $query->getTableInfo('', 'type');
|
||||
} else {
|
||||
$type = [];
|
||||
foreach ((array) $this->field as $key => $val) {
|
||||
if (is_int($key)) {
|
||||
$key = $val;
|
||||
$val = 'varchar';
|
||||
}
|
||||
$type[$key] = $val;
|
||||
}
|
||||
}
|
||||
$query->setFieldType($type);
|
||||
$this->field = array_keys($type);
|
||||
$query->allowField($this->field);
|
||||
}
|
||||
|
||||
if (!empty($this->pk)) {
|
||||
$query->pk($this->pk);
|
||||
}
|
||||
@@ -632,7 +614,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
// 检测字段
|
||||
if (!empty($this->field)) {
|
||||
foreach ($this->data as $key => $val) {
|
||||
if (!in_array($key, $this->field) && !array_key_exists($key, $this->field)) {
|
||||
if (!in_array($key, $this->field)) {
|
||||
unset($this->data[$key]);
|
||||
}
|
||||
}
|
||||
@@ -780,9 +762,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
public function allowField($field)
|
||||
{
|
||||
if (true === $field) {
|
||||
$field = $this->db()->getTableInfo('', 'type');
|
||||
$this->db()->setFieldType($field);
|
||||
$field = array_keys($field);
|
||||
$field = $this->db()->getTableInfo('', 'fields');
|
||||
}
|
||||
$this->field = $field;
|
||||
return $this;
|
||||
|
||||
@@ -43,10 +43,6 @@ class Query
|
||||
protected $name = '';
|
||||
// 当前数据表主键
|
||||
protected $pk;
|
||||
// 当前表字段类型信息
|
||||
protected $fieldType = [];
|
||||
// 当前允许的字段列表
|
||||
protected $allowField = [];
|
||||
// 当前数据表前缀
|
||||
protected $prefix = '';
|
||||
// 查询参数
|
||||
@@ -741,11 +737,11 @@ class Query
|
||||
}
|
||||
if (true === $field) {
|
||||
// 获取全部字段
|
||||
$fields = !empty($this->allowField) && ('' == $tableName || $this->getTable() == $tableName) ? $this->allowField : $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
||||
$fields = $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
||||
$field = $fields ?: ['*'];
|
||||
} elseif ($except) {
|
||||
// 字段排除
|
||||
$fields = !empty($this->allowField) && ('' == $tableName || $this->getTable() == $tableName) ? $this->allowField : $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
||||
$fields = $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
||||
$field = $fields ? array_diff($fields, $field) : $field;
|
||||
}
|
||||
if ($tableName) {
|
||||
@@ -1260,35 +1256,6 @@ class Query
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置数据表字段
|
||||
* @access public
|
||||
* @param string|array $field 字段信息
|
||||
* @return $this
|
||||
*/
|
||||
public function allowField($field)
|
||||
{
|
||||
if (true === $field) {
|
||||
$field = $this->getTableInfo('', 'fields');
|
||||
} elseif (is_string($field)) {
|
||||
$field = explode(',', $field);
|
||||
}
|
||||
$this->allowField = $field;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置字段类型
|
||||
* @access public
|
||||
* @param array $fieldType 字段类型信息
|
||||
* @return $this
|
||||
*/
|
||||
public function setFieldType($fieldType = [])
|
||||
{
|
||||
$this->fieldType = $fieldType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定数据表主键
|
||||
* @access public
|
||||
@@ -1421,13 +1388,13 @@ class Query
|
||||
// 获取当前数据表字段信息
|
||||
public function getTableFields($options)
|
||||
{
|
||||
return !empty($this->allowField) ? $this->allowField : $this->getTableInfo($options['table'], 'fields');
|
||||
return $this->getTableInfo($options['table'], 'fields');
|
||||
}
|
||||
|
||||
// 获取当前数据表字段类型
|
||||
public function getFieldsType($options)
|
||||
{
|
||||
return !empty($this->fieldType) ? $this->fieldType : $this->getTableInfo($options['table'], 'type');
|
||||
return $this->getTableInfo($options['table'], 'type');
|
||||
}
|
||||
|
||||
// 获取当前数据表绑定信息
|
||||
@@ -2003,9 +1970,6 @@ class Query
|
||||
$model = $this->model;
|
||||
$data = new $model($data);
|
||||
$data->isUpdate(true, isset($options['where']['AND']) ? $options['where']['AND'] : null);
|
||||
if ($this->allowField) {
|
||||
$data->allowField($this->allowField);
|
||||
}
|
||||
// 关联查询
|
||||
if (!empty($options['relation'])) {
|
||||
$data->relationQuery($options['relation']);
|
||||
|
||||
Reference in New Issue
Block a user