如何强制学说从数据库重新加载数据? [英] How do I force doctrine to reload the data from the database?
问题描述
我在 symfony2.1 安装中使用了学说/mongodb 1.0.0-BETA1.
I'm using doctrine/mongodb 1.0.0-BETA1 in a symfony2.1 install.
所以我试图强制我的存储库从我的数据库中调用数据,而不是使用它缓存的对象.
So i'm trying to force my repository to call data from my database instead of using the object it has cached.
$audit = $dm->getRepository("WGenSimschoolsBundle:Audit")->findOneById("xxxx");
.... do something somewhere to change the object ....
此时如果我打电话
$audit = $dm->getRepository("WGenSimschoolsBundle:Audit")->findOneById("xxxx");
审计数据没有改变.它仍然具有它最初获取的对象.如果我尝试
The audit data hasn't changed. It still has the object it originally fetched. If I try to
$dm->refresh($audit)
我得到了同样的东西.无论如何,我是否可以返回数据库获取值?
I get the same thing. Is there anyway for me to go back to the database for the value?
推荐答案
您是否已将更改刷新到 $audit
对象?
Have you flushed your changes to the $audit
object?
$audit = $dm->getRepository("WGenSimschoolsBundle:Audit")->findOneById("xxxx");
//do something somewhere to change the object
$dm->flush();
<小时>
每次执行 findBy(...)
或 findOneBy(...)
时,它实际上都会从数据库中获取一个新文档.(您应该在 Symfony 分析器中看到查询)
Every time you do a findBy(...)
or findOneBy(...)
it actually fetches a new document from the DB. (you should see the query in the Symfony profiler)
用 find() 代替,它将从他的内部代理缓存中获取文档.文档将保留在代理缓存中,直到您调用 $dm->clear()
方法.
With a find() instead, it will fetch the document from his internal proxy cache.
The Documents stay in the proxy cache until you call the $dm->clear()
method.
这篇关于如何强制学说从数据库重新加载数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!