Search code examples
shopwareshopware6

Delete entry from Entity for current language


I've created a custom entity including translations for several fields and through the admin you can enter new entries.

What I've noticed is if you delete an entry from the list view, it will delete the entry from the database for all languages.

Is it possible to only remove the translation entry for the current language? For example if I've got an entry in NL and EN and EN is selected, then it would make more sense to me that only the EN entry is deleted in the translation table and not both.


Solution

  • Translations are just a special one2many relation, being automatically resolved for the current language, and as such will also be deleted like any one2many relation when the owning side is deleted.

    If you want your entity to be language specific, so it may be deleted for one language only, you'll have to add and maintain a many2one relation to LanguageDefinition on the entity itself. Then you wouldn't need translated fields at all, as the fields of the entity would already be language specific. However you'd have to filter the entities by language whenever they're loaded, by using criteria filters.

    So it's a trade-off you'll have to decide on if it's worth the effort. Either use an owning side entity with translations and have the convenience of it using the current context's language to resolve the translations, but have all translations be deleted if the owning side is deleted. Or associate the entity with a language directly but have the additional effort of having to set/filter by the language manually when saving/loading.