Hello, I have such a problem: you need to display data on the same page (page.hbs) of different tables. I use nodejs, orm sequelize, mysql db, Handlebars. With the getter method, the page.hbs page needs to get data from two different tables. Here is my code:
models:
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); }); } routes:
module.exports = function (app, passport) { app.get('/page_admin', isLoggedIn, authController.page_admin); .........
Please help (I do not really understand how to access two tables in one get request, as I understand it is necessary to correct authcontroller.js (merge queries)) Thanks in advance for your help.