获取器无法默认设置额外字段
Author: Jay-L1Created Sep 14, 2020Updated Sep 15, 2020
easyswoole 3.3.7、orm组件版本号 [1.4.26]
设置了获取器,但是数据中没有额外的字段
排查情况和最小复现脚本
/**
* 控制器
* @return bool
* @throws Throwable
*/
public function test()
{
$list = TestAModel::create()->all();
foreach ($list as &$v) {
$v->easyswoole = $v->easyswoole; // 有额外字段
$v->toArray(); //没有额外字段
}
unset($v);
$this->response()->write(json_encode($list, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
$this->response()->withHeader('Content-type', 'application/json;charset=utf-8');
$this->response()->withStatus(200);
return true;
}
/**
* 模型
* @return array|mixed|null


* @throws Throwable
*/
protected function getEasySwooleAttr($value, $data)
{
if ($data['uid']) {
return TestModel::create()->where('id', $data['uid'])->scalar('name');
}
return '';
}
Source: easy-swoole/orm