framework
framework copied to clipboard
tp6模型save方法丢失精度, decimal(36,18) 设置模型属性 `$type` 为 `string` 无效
遇到一个奇怪的问题,
数据库字段 money 类型 decimal(36,18)
当使用模型方法 $model->save($data) 更新数据,
超过11位后面的小数会丢失
例如将价格设置为:100.123456789012345678
将得到: 100.12345678901
$data = [
"money" => "100.123456789012345678",
];
$save = $model->save($data);
设置模型属性 $type 为 string 无效:
还是会将 money 转换为 100.12345678901
// 设置字段自动转换类型
protected $type = [
'money' => 'string', // 无效
];
必须设置完整 $schema 字段信息, string 才生效:
// 设置字段信息
protected $schema = [
"id" => "int",
"title" => "string",
"description" => "string",
"image" => "string",
"money" => "string", // 有效
"sort" => "int",
"status" => "int",
"remark" => "string",
"create_time" => "int",
"update_time" => "int",
];
此时通过 $model->save($data) 不再丢失精度
得到 100.123456789012345678
能否修复 $type 模型属性对 string 的支持, 以及模型默认save方法对decimal的转换问题?
有检查过实际生成的sql吗