top-think / top-think/think-orm
getChangedData() 松散比较导致前导零丢失
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 437
- Forks
- 188
- PR merge metrics
- No merged PRs in 30d
Description
问题:
在更新编号之类的字符串前导0更新失效。
更新带前导零的字符串值(如 "6" → "06")时,值没有变化。
根本原因是 getChangedData() 使用 PHP 的 != 比较,而 "06" != "6" 返回 false。
复现:
$row = Model::find(1);
$row->code = '06'; // 原值是 '6'
$row->save();
// 结果: code 仍然是 '6',前导零丢失
修复:
Attribute.php 第 380 行:
return is_object($a) || $a != $b ? 1 : 0;
改为:
return is_object($a) || $a !== $b ? 1 : 0;
影响: 所有使用 save() 更新带前导零字符串字段的模型
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Attribute.php around line 380 and reproduce the save flow described in the issue, changing a stored string from "6" to "06". Confirm that the updated value is persisted with its leading zero and verify that existing ORM behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- database
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 85/100