我从Sequelize返回了以下数据,但我想从键表中获得另一个值而不是ID_Key(例如:键名,该值在键表中可用)。
[
{"ID_Translation":1,"ID_Language":1,"ID_Key":2,"TargetText":"TextTranslation2"},
{"ID_Translation":2,"ID_Language":1,"ID_Key":1,"TargetText":"TextTranslation1"},
{"ID_Translation":3,"ID_Language":1,"ID_Key":3,"TargetText":"TextTranslation3"}
]
我的查询:
Translation.findAll({
where: {
ID_Language: 1,
}
}).then(Translations => {
console.log("All Translations:", JSON.stringify(Translations));
});
谢谢
你联想translations
用Key-table
?您可以在查询中include
使用include
属性来关联模型。例如:假设您有一个与模型Key
关联的命名Translations
模型,并且在这些模型之间具有1-N关联,如下所示:
Key.hasMany(Translation, {foreignKey: 'ID_Key'});
Translation.belongsTo(Key, {foreignKey: 'ID_Translation'});
你可以做:
Translation.findAll({
where: {
ID_Language: 1,
},
include: [
Key
],
})
当您全部获取时Translation
,Key
由于关联,您将在翻译对象中拥有一个属性。那就是eager loading
。
查看更多有关文档的信息:http : //docs.sequelizejs.com/manual/models-usage.html#eager-loading
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句