top-think / top-think/think-orm

模型save后不会自动更新cache

Open
#100 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
437
Forks
188
PR merge metrics
No merged PRs in 30d

Description

如下代码,goods_name字段已设置成其他的值,但是最后查询出来的还是修改前的值

$goods = GoodsModel::cache(true,600)->find(100532);
$goods->goods_name = '213123';
$goods->save();//不会更新缓存
dump( GoodsModel::cache(true,600)->find(100532)->toArray());//查询出的goods_name不是213123而是修改之前的

但是直接使用db类操作却不会有问题

$goods = Db::name('goods')->cache(true,600)->find(100532);
$goods['goods_name'] = '123212';
Db::name('goods')->cache(true,600)->update($goods);//会更新缓存
dump(Db::name('goods')->cache(true,600)->find(100532));//查询出goods_name=123212

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two snippets in the issue and compare the model save path with the Db update path when caching is enabled. Trace the cache behavior used by GoodsModel::save() and verify that a subsequent cached find returns the updated goods_name after the fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.