Reputation: 41
Similarly to this question, I got some problems with how doctrine caches/hydrates the relations of the result of my query.
Now I know I can fix the issue by calling refresh/refreshRelated, but is there a way to disable the hydration cache for a table/temporarily? Especially when using joins in the select such that the example code becomes:
$result2 = Doctrine_Query::create()
->leftJoin('s.School sc')
->from('Student s')
->execute();
you really want Doctrine to use the data from your join instead of using the cached hydrated result from the previous select.
Is there a way of doing this?
Thanks in advance!
Upvotes: 4
Views: 2790
Reputation: 956
I think your solution with the refreshRelated is okay, but if you don't need these items in the cache. You can set
Doctrine_Manager::connection()->setAttribute(Doctrine_Core::ATTR_AUTO_FREE_QUERY_OBJECTS, true );
By this, Doctrine will automatically call free() on each query at the end, so it won't cache its result, and also will keep memory footprint a bit lower.
Upvotes: 0
Reputation: 713
I think it should hydrate with the query result by default, unless you have changed Doctrine_Core::ATTR_HYDRATE_OVERWRITE
. You can check the value with:
$doctrineManager = Doctrine_Manager::getInstance();
$val = $doctrineManager->getAttribute(Doctrine::ATTR_HYDRATE_OVERWRITE);
When you call refresh(), it forces this value to true, and does the query again, and then restores the setting. If yours happens to be false, you can change it with $doctrineManager->setAttribute
Upvotes: 2