0

I have a problem with Cache of Dql query, I have this 6 lines:

$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();

I Have try that (before $query->getResult()) :

$query->useQueryCache(false);
$query->setQueryCacheLifetime(0);
$query->useResultCache(false);
$query->setQueryCacheDriver(null);

But I always have same results in $result1 and $result2 => there are equals and contain the results of the first query.

Some one can say me how solve it ?

Thanks

Nicolo
  • 1
  • 3

1 Answers1

0

I have just find that Cms\Days stay in the EntityManager ( _em ) for the 2 querys so between the 2 getResult we can add :

$this->_em->clear();

or make a foreach on the result to detach the element :

foreach($result1 as $element) {
    $this->_em->detach($element);
}

Thanks Doctrine Lazy Loading ... :'(

Nicolo
  • 1
  • 3