Locastic / ApiPlatformTranslationBundle

Translation bundle for ApiPlatform based on Sylius translation
MIT License
85 stars 28 forks source link

Automatically add translation when it does not exist #55

Open rsereir opened 2 years ago

rsereir commented 2 years ago

Hello,

I have an entity without any translation and i see in my Symfony profiler multiple requests to query current locale, and default locale, then if no translation, insert new translation.

The problem is i don't want to add new translation automatically.

I think, when i call $this->getTranslations('unavailable locale')->getName(), i have a new translation object created with name = null but with a $entityManager->flush() for other reasons after this getTranslations(), this object is persisted to database.

This is my error: An exception occurred while executing a query: SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column \"template\" of relation \"email_translation\" violates not-null constraint\nDETAIL: Failing row contains (1ecd36ca-d8ef-6572-bb2a-c1eda6aadb28, 1ecd23cc-a924-61aa-8575-d1e3b0741a73, fr, null).

kevinG73 commented 2 years ago

Hello @rsereir , you can use Symfony events to do this or use data persisters .

rsereir commented 2 years ago

@kevinG73 i don't want to persist, but the bundle persist not existing translations when i try to get this

kevinG73 commented 2 years ago

I have an entity without any translation and i see in my Symfony profiler multiple requests to query current locale, and default locale, then if no translation, insert new translation.

The problem is i don't want to add new translation automatically.

In the dataPersister you will do the processing that suits you

rsereir commented 2 years ago

What ? No datapersister is trigged, it's a GET route like "/api/issues" but i have an entitymanager->persist() of IssueViewer entity in this route that cause IssueTranslation persist cause by my $issue->getTranslations()->getName() in my /api/issues response.