Javascript orm sequelize在单个页面加载中从两个不同的表执行查询
我有这个问题:需要在一个页面(page.hbs)不同的表上显示数据。我在使用nodejsormsequelize,mysql数据库,把手。当get方法转到page.hbs页时,需要从两个不同的表中获取数据。这是我的密码: 型号:Javascript orm sequelize在单个页面加载中从两个不同的表执行查询,javascript,mysql,node.js,sequelize.js,Javascript,Mysql,Node.js,Sequelize.js,我有这个问题:需要在一个页面(page.hbs)不同的表上显示数据。我在使用nodejsormsequelize,mysql数据库,把手。当get方法转到page.hbs页时,需要从两个不同的表中获取数据。这是我的密码: 型号: var roof_type = sequelize.define('roof_type', { id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey:
var roof_type = sequelize.define('roof_type', {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false
},
description: {
type: DataTypes.STRING(50),
allowNull: true
}
});
return roof_type;
var garret_type = sequelize.define('garret_type', {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false
},
description: {
type: DataTypes.STRING(50),
allowNull: true
}
});
return garret_type;
authcontroller.js:
exports.page_admin = function (req, res) {
db.roof_type.findAll({
description: 'description ASC'
}).then(function (data) {
var hbsObject = {
roof_types: data
};
res.render('page_admin', hbsObject);
});
}
exports.page_admin = function (req, res) {
db.garret_type.findAll({
description: 'description ASC'
}).then(function (data) {
var hbsObject = {
garret_types: data
};
res.render('page_admin', hbsObject);
});
}
路线:
module.exports = function (app, passport) {
app.get('/page_admin', isLoggedIn, authController.page_admin);
请提供帮助(我真的不知道如何让一个查询访问两个表,因为我知道您需要修复authcontroller.js(合并请求)),提前感谢您的帮助。使用
Promise.all([db.findAll(tableA), db.findAll(tableB)])
.then((data) => {
//data[0] is response from tableA find
// data[1] is from tableB
})