加载同一 Doctrine_Record 的多个版本时遇到问题

发布于 2024-11-18 10:53:15 字数 474 浏览 2 评论 0原文

以下代码片段演示了 Doctrine 的一些特殊行为。

$user = Doctrine::getTable('User')->find(1);
$user->name = 'Zoppy';

// This line prevents the subsequent $user->save() from working as expected
$old_user = Doctrine::getTable('User')->find(1);

$user->save();

// Does not print 'Zoppy'
echo Doctrine::getTable('User')->find(1)->name . "\n";

这是怎么回事?

在执行保存之前是否有某种方法可以加载旧版本的记录?似乎 Doctrine 正在某处缓存某些内容 - 到底是什么,以及如何将其关闭! (至少暂时是这样。)

The following code snippet demonstrates some peculiar behaviour from Doctrine.

$user = Doctrine::getTable('User')->find(1);
$user->name = 'Zoppy';

// This line prevents the subsequent $user->save() from working as expected
$old_user = Doctrine::getTable('User')->find(1);

$user->save();

// Does not print 'Zoppy'
echo Doctrine::getTable('User')->find(1)->name . "\n";

What is going on here?

Is there some way to load the old version of a record before executing a save? It seems that Doctrine is caching something somewhere -- what exactly, and how do I turn it off! (At least temporarily.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸩远一方 2024-11-25 10:53:15

我最近问了一个类似的问题,尽管我是用关系来表达的。但答案是,这取决于 Doctrine 中缓存的本质。学说是将含水的物体保留在记忆中。您可以克隆该对象,但一旦遵循任何关系,您就会回到原点。

I asked a similar question recently, although I phrased it in terms of relationships. The answer though is that this is down to the nature of caching in Doctrine. Doctrine is keeping hydrated objects in memory. You can clone the object, but as soon as you follow any relationships you'll be back to square one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文