删除当前语言的实体条目

huangapple go评论44阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年4月6日 21:36:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950186.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定