改进Model类的field属性定义 varchar类型的属性可以不用定义类型,例如:

protected $field = [
   'id'=>'int','name','email','create_time'=>'int',
];
This commit is contained in:
thinkphp
2016-08-10 16:08:01 +08:00
parent a1edf89aec
commit 1c05f6d31d

View File

@@ -154,12 +154,19 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
if (!empty($this->field)) {
if (true === $this->field) {
$this->field = $this->db()->getTableInfo('', 'type');
}
if (is_array($this->field) && key($this->field) !== 0) {
$query->setFieldType($this->field);
$this->field = array_keys($this->field);
$type = $this->db()->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);
}