原则结果缓存错误与LEFT JOIN ... WITH条件 [英] Doctrine result cache bug with LEFT JOIN ... WITH condition

查看:151
本文介绍了原则结果缓存错误与LEFT JOIN ... WITH条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我需要在这里发布问题之前,我倾向于找到答案,但今天我似乎无法找出错误。

I tend to find answers before I need to post a question here, but today I can't seem to find out what is wrong.

我们正在使用Doctrine 2.1.2在Symfony 2应用程序中,而在存储库中,我们有两种使用几乎相同查询的方法。
方法A和方法B之间的唯一区别在于,这两个查询共有的条件是添加到JOIN中。

We're using Doctrine 2.1.2 in a Symfony 2 app, and in a repository we have two methods that use almost the same query. The only difference between method A and method B is that there is a condition added to a JOIN that is common to both queries.

问题是原则似乎对这两个查询使用相同的结果缓存。
当我们调用方法A时,方法B使用来自A的缓存,而另一种方式。

The problem is that Doctrine seems to use the same result cache for both queries. When we call method A, method B uses the cache from A, and the other way around.

我一直在使用expireResultCache(true)和useResultCache false),无效。

I have been using expireResultCache(true) and useResultCache(false), to no avail.

以下是查询的样子:

-- method A

SELECT DISTINCT a, b, c FROM MyBundle:ObjectA a INDEX BY a.id
LEFT JOIN a.fkObjectB b
LEFT JOIN a.fkObjectC c

-- method B
SELECT DISTINCT a, b, c FROM MyBundle:ObjectA a INDEX BY a.id
LEFT JOIN a.fkObjectB b WITH b.some_field IS NULL
LEFT JOIN a.fkObjectC c

当我使用getSQL()时,我看到它们会按预期的方式导致不同的查询。生成的查询在数据库中独立运行时会产生不同的结果。

When I use getSQL(), I see that they result in different queries as expected. The generated queries, when run independantly in database, do generate different results.

这使我相信这可能是一个令人讨厌的结果缓存错误,Doctrine不缓存JOIN的条件,但只有表名。

This leads me to believe that it may be an annoying result cache bug, where Doctrine does not cache the conditions for JOINs, but only the table names.

这是一个错误,还是有什么我可以做的?

Is this a bug, or is there something I can do?

编辑仍然在Doctrine 2.1.6中发生。

EDIT Still happening in Doctrine 2.1.6.

推荐答案

a href =https://stackoverflow.com/questions/9331308/doctrine-result-cache-bug-with-left-join-with-condition#comment14202428_9334183> michel v的评论,Doctrine 2提取相同的对象实例都经过身份图模式

Just to expand on michel v's comment, Doctrine 2 is fetching the same object instance both times via the identity map pattern.

致电:

EntityManager#clear()

清除身份p并强制EntityManager从数据库中获取对象的新副本。

clears the identity map and forces the EntityManager to fetch a fresh copy of the object from the database.

这篇关于原则结果缓存错误与LEFT JOIN ... WITH条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆