我的Dql查询缓存有问题,我有这6行:
$dql = "SELECT d, c FROM \Cms\Day d LEFT JOIN d.contents c WITH c INSTANCE OF Cms\Message ORDER BY d.num ASC";
$query = $this->_em->createQuery($dql);
$result1 = $query->getResult();
$dql = "SELECT d, c FROM \Cms\Day d LEFT JOIN d.contents c WITH c INSTANCE OF Cms\Article ORDER BY d.num ASC";
$query = $this->_em->createQuery($dql);
$result2 = $query->getResult();
我试过(在$ query-> getResult()之前):
$query->useQueryCache(false);
$query->setQueryCacheLifetime(0);
$query->useResultCache(false);
$query->setQueryCacheDriver(null);
但我在$ result1和$ result2 =>中总是有相同的结果。有等于并包含第一个查询的结果。
有人可以说我怎么解决它?由于
答案 0 :(得分:0)
我刚刚发现Cms \ Days留在EntityManager(_em)中的2个查询,所以我们可以添加2个getResult:
$this->_em->clear();
或对结果进行foreach以分离元素:
foreach($result1 as $element) {
$this->_em->detach($element);
}
感谢Doctrine Lazy Loading ...:'(