Using Gedmo Translatable Doctrine extension for Symfony 2, I'm having some strange behaviour/bug with the DB queries.
To get a list of elements with translated attributes, I use the 'SetHint' method on the query, as explained in the documentation:
$query->setHint(
Query::HINT_CUSTOM_OUTPUT_WALKER,
'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
);
$query->setHint(TranslatableListener::HINT_TRANSLATABLE_LOCALE, $locale);
This works rather well, but in some cases, (when I'm not in the default locale, and then being needing translations), the query only returns one or two results, instead of the full result set.
A strange things about that is that it only happens on the production server (under Linux), and cannot be reproduced on local WAMP server, neither in dev or production environment.
I finally figured out that the case was happenning when I tried to load a set of entities not having to be translated themselves, but having sub-entities (OneToMany) attached and joined to the query which had to be translated.
The reason of that would be that the main query being done on a non-translatable entity, the 'setHint' method was not applied to the query, so that the sub-elements had trouble to be translated, or something like that..
So in a first time, I managed to solve that issue by applying Gedmo Translatable on the parent entity's repository, in order to apply the setHint method to the query, passing the desired locale to it.
BUT I am enjoying this issue once again.
Has anyone been confronted to this before? Is there a way of finding out what's happening here? Does God exists?
Thank you for your answers.
Edit: After some research and debug, I found out that the getArrayResult() returns the full set.. Meaning that the problem seems to be located in Doctrine's Entity Object Hydratation.
............... (help!).................
After having submitted the issue to Gedmo/Translatable author l3pp4rd, he finally found out it was a query cache issue.
The solution was to turn Doctrine Query Cache to false:
$query = $qb->getQuery()->useQueryCache(false);
So my complete translatable query code, in order to have translated fields directly in result's hydrated objects with one query is:
$query = $qb->getQuery()->useQueryCache(false);
$query->setHint(
Query::HINT_CUSTOM_OUTPUT_WALKER,
'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
);
$query->setHint(TranslatableListener::HINT_TRANSLATABLE_LOCALE, $locale);
return $query;
Thank you L3pp4rd!