英文:
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.
答案1
得分: 0
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.
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论