In my Symfony / Doctrine application, I have a query that orders RANDOM (). I call the same method several times, but it looks like the query result is cached.
Here is my corresponding code:
$query = $table->createQuery('p') ->select('p.*, RANDOM() as rnd') ->orderBy('rnd') ->limit(1) ->useQueryCache(null) ->useResultCache(null); $result = $query->fetchOne();
Unfortunately, the same record is returned every time, regardless of the fact that I pass null both useQueryCache and useResultCache . I tried using false instead of null , but that didn't work either. Finally, I also tried calling both setResultCacheLifeSpan(0) and setResultCacheLifeSpan(-1) , but not a single call made a difference.
Any insight on how to prevent caching, as I want every time I call this method, I select a different random string?
Edit: I also tried calling clearResultCache() , but it only ended up causing the error: "The result cache driver is not initialized."
Edit 2: As requested here, SQL is generated by calling $query->getSqlQuery() :
SELECT c.id AS c__id, c.name AS c__name, c.image_url AS c__image_url, c.level AS c__level, c.created_at AS c__created_at, c.updated_at AS c__updated_at, RANDOM() AS c__0 FROM cards c ORDER BY c__0 LIMIT 1
Matt Huggins Feb 07 2018-11-11T00: 00Z
source share