问题描述
我尝试协会
Currency_Info.hasMany(DEAL_INFO,{foreignKey: 'selling_CURRENCY'})
COUNTERPARTY_INFO.hasMany(DEAL_INFO,{foreignKey: 'COUNTER_PARTY_CODE'})
DEAL_INFO.belongsTo(Currency_Info,{foreignKey: 'selling_CURRENCY',targetKey: 'Ccy_Code'})
DEAL_INFO.belongsTo(COUNTERPARTY_INFO,{foreignKey: 'COUNTER_PARTY_CODE',targetKey: 'COUNTERPARTY_CODE'})
var conCursor = await DEAL_INFO
.findAll({
include: [{model: COUNTERPARTY_INFO,required: true,model: Currency_Info,required: true }]
})
.catch((error) => {
console.log(error.toString());
res.status(400).send("-1" + error)
})
但是没有得到想要的结果
通过(DEAL_INFO.selling_CURRENCY = currency.CCY_CODE)内部加入CURRENCY
我如何获得两个内部联接 1.在(DEAL_INFO.selling_CURRENCY = currency.CCY_CODE)上内部加入CURRENCY 2.在(deal_info.counter_party_code = peery_info.counterparty_Code)上内部加入对等方信息
解决方法
您可以在include
内使用模型列表
类似这样的东西:
var conCursor = await DEAL_INFO.findAll({
include: [
{model: COUNTERPARTY_INFO,required: true},{model: Currency_Info,required: true }
]
})
.catch((error) => {
console.log(error.toString());
res.status(400).send("-1" + error)
})
希望您得到了答案!