我有表categories
和字段title
,也有表translations
和表fk
categryId
和region
和title
保持翻译。表已关联。
我有一个场景,说明如何从前端到数组中的控制器进行转换:
const translations = [
{ region: 'uk', title: 'title_in_uk' },
{ region: 'dk', title: 'title_in_dk' }
]
我的目标更新会翻译成新的。最好的方法可能会像这样覆盖:
category.setTranslations(translations)
但不确定还是这种方式完全存在。
答案 0 :(得分:-2)
要更新字段,您必须先找到其文档,然后才很容易更新它。 您可以使用以下代码更新字段
const model = await model.findOne({
where: { title: 'title_in_uk' }
}).catch(err => {console.error('Error: ' + err)});
if (model) {
const updateRecord = await model.update({
// put the fields to be updated here containing the new values
}).catch(err => {console.error('Error: ' + err)});
}
您的问题不清楚...请让我知道您是否想要其他东西