So I had a complex Entity with a few sub-entities managed by OneToManys and ManyToManys.
Using the basic setMaxResults()
and setFirstResult()
methods were returning less than the desired number of results (when executing the runnable query, I get back my set limit of results, but there are repeat records which Doctrine then trims down and returns the unique records only). Looking through stackoverflow I came across the Paginator
Doctrine Tool class.
The issue that I have, is that I need to cache the results. I use Doctrine's ApcCache interface, but when I try to save it to the cache, I get back Exception: Serialization of 'Closure' is not allowed
. But the Paginator class doesn't seem to allow me to acquire the the results of the query (just the 10). And obviously when I do this:
$results = new Paginator($query, $fetchJoin = true);
return $results->getQuery()->getResult();
Im back to my original problem of getting less than my desired limit of records (as now we're going back to the original method of getting results)
I just want the array of results, so I may serialize and cache it. What's the best approach to doing that?
Thanks
EDIT
Right now, I am adding a foreach loop and collecting the records into an array. Which seems to work, but I wonder if theres a better way of handling this, than adding another loop in each of my Repository methods...
$results = new Paginator($query, $fetchJoin = true);
$return = [];
foreach($results as $result) {
$return[] = $result;
}
$cache->save($cacheKey, $return, 300);
return $return;