模型类的field属性定义简化 取消Query类的allowField和setFieldType方法及相关属性 交给数据表字段缓存

This commit is contained in:
thinkphp
2016-09-18 20:12:32 +08:00
parent 8c86ed3656
commit d2b75581fb
2 changed files with 6 additions and 62 deletions

View File

@@ -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;