Skip to content

修复 find => force => save 这个流程下update_time 不更新的问题#852

Open
ichynul wants to merge 1 commit into
top-think:4.0from
ichynul:patch-1
Open

修复 find => force => save 这个流程下update_time 不更新的问题#852
ichynul wants to merge 1 commit into
top-think:4.0from
ichynul:patch-1

Conversation

@ichynul

@ichynul ichynul commented Jun 22, 2026

Copy link
Copy Markdown
Contributor
$user = User::find(1);
$res = $user->force()->save(['name' => '小明' . time()]);
//结果:表中`update_time`不更新。

原因分析,find查询出表中的所有字段,包含update_time
当调用->force()后,更新的时候不检查是否需要更新并unset()未改变字段。
把查询出来的update_time值原样写回去。
autoDateTime方法中,判断当保存的数据中update_time字段空才会把它设置为当前时间

```php
$user = User::find(1);
$res = $user->force()->save(['name' => '小明' . time()]);
//结果表中`update_time`不更新。
```

原因分析,find查询出表中的所有字段,包含`update_time`。
当调用->force()后,更新的时候不检查是否需要更新并unset()未改变字段。
把查询出来的`update_time`值原样写回去。
在`autoDateTime`方法中,判断当保存的数据中`update_time`字段空才会把它设置为当前时间
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.98%. Comparing base (899093b) to head (3419730).

Additional details and impacted files
@@            Coverage Diff            @@
##                4.0     #852   +/-   ##
=========================================
  Coverage     51.98%   51.98%           
- Complexity     3530     3531    +1     
=========================================
  Files            74       74           
  Lines          8314     8314           
=========================================
  Hits           4322     4322           
  Misses         3992     3992           
Flag Coverage Δ
unittests 51.98% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant