我想要使用Sequelize原始查询的关联模型吗?这可能吗?
在location.js(模型)中
Location.belongsTo(models.route, {
as: 'defRouteMon',
foreignKey: {
allowNull: true
}
});
Location.belongsTo(models.route, {
as: 'defRouteTue',
foreignKey: {
allowNull: true
}
});
呼叫查询:
let options = {
include: [{ model: models.route, as: 'defRouteMon' }, [{ model: models.route, as: 'defRouteTue' }],
model: models.location
};
sequelize.query("SELECT * FROM LOCATION",options)
实际结果:
{
"id": "00000",
"name": "test",
"defRouteMonId": "004",
"defRouteTueId": "004",
}
预期结果
{
"id": "00000",
"name": "test",
"defRouteMon": {
"id": "004"
"name": "mon004"
},
"defRouteMonId": "004",
"defRouteTue" : {
"id": "004"
"name": "mon004"
},
"defRouteTueId": "004",
}
我正在使用“ sequelize”:“ ^ 3.33.0”