Sonata Admin & KNP Doctrine Behaviour Translations

339 views Asked by At

We have configured the translations using Doctrine Behaviours. But in the sonata admin list view it displayed all the translations of the entity those are saved using the Doctrine behaviour. But we only need to show the current locale translations. I created a function in the entity and got the translation from the transnationals table. And it worked fine.

But Now it became a performance issue. As on each record it consults the translations table and a query is executed now there are around 3000 rows to be displayed on a view and its collapsing the system.

To Implement it in forms for take translations input i have configured a2lix translation form.

Is there any way to display the single translation using current locale in the sonata Admin?

1

There are 1 answers

0
Baran On BEST ANSWER

You have to place the joins with the translations table it will reduce the number of queries those consult database for each record. then it will be checking form the current object.

Like:

public function createQuery($context = 'list') {
    $query = parent::createQuery($context);

    $query->addSelect('tl');
    $query->innerJoin($query->getRootAlias() . ".translations", "tl");

    return $query;
}

It will be working in Sonata Admin. If you want to do this other than sonata admin you can put joins in repository.