Closed heavenqq closed 6 years ago
php --ri swoole
php -v
Details 当数据库存在下划线字段时,如:add_time,实体会生成 setAddTime方法,然后用Swoft\Db\Model的fill方法向数据库写入内容时,会与实体生成setAddTime方法不兼容,无法更新add_time字段
// paste output here $data =[ 'add_time'=>time() ] $member = new EwgMember(); $member->fill($data)->save()->getResult();
Provide minimal script to reproduce the issue
// paste code 实体的setAddTime方法 public function setAddTime(int $value): self { $this->add_time = $value; return $this; } //Swoft\Db\Model的fill方法 public function fill(array $attributes): self { foreach ($attributes as $name => $value) { $methodName = sprintf('set%s', ucfirst($name)); if (method_exists($this, $methodName)) { $this->$methodName($value); } } return $this; }
建议属性名称,统一定义成驼峰,再映射数据库字段,
他这是通过命令根据表生成的,应该在fill 时自动处理下
php --ri swoole
)php -v
)Details 当数据库存在下划线字段时,如:add_time,实体会生成 setAddTime方法,然后用Swoft\Db\Model的fill方法向数据库写入内容时,会与实体生成setAddTime方法不兼容,无法更新add_time字段