Gedmo Translatable load multiple translations

Viewed 92

When using Gedmo Translatable with Symfony it seems that I have 2 different choice to load the translations:

  • let the ORM load them with postLoad, this will trigger a lot of these queries:
SELECT t0.id AS id_1, t0.locale AS locale_2, t0.field AS field_3, t0.content AS content_4, t0.object_id AS object_id_5 FROM product_translation t0 WHERE t0.object_id = ?
  • use a query hint (it will make a left join):

->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, TranslationWalker::class)

LEFT JOIN product_translation t1_ ON t1_.locale = 'en' AND t1_.field = 'name' AND t1_.object_id = p0_.id LEFT JOIN product_translation t2_ ON t2_.locale = 'en' AND t2_.field = 'description' AND t2_.object_id = p0_.id

Unfortunately the second solution will use a LEFT JOIN and the query could become a little slow.

Is it possible to use the first solution (separate query) but load all the translations at once instead of one query for every item?

I tried using:

->setFetchMode(Product::class, 'translations', ClassMetadata::FETCH_EAGER)

But unfortunately it doesn't work.

0 Answers
Related