【发布时间】:2017-07-10 23:04:55
【问题描述】:
我有这个问题:需要在一页(page.hbs)不同的表上显示数据。我正在使用 nodejs orm sequelize、mysql 数据库、Handlebars。当get方法到page.hbs页面需要从两个不同的表中获取数据。这是我的代码:
型号:
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(merge requests) )提前感谢您的帮助。
【问题讨论】:
标签: javascript mysql node.js sequelize.js