Am newbie to RDBMS and Sequelize as well wanted to explore more in those now am struck up with JOINS. I don't know how to perform JOINS via SEQUELIZE. I have 3 tables USERS,ORDERS,PRODUCTS ORDERS table contains USERS,PRODUCTS primary key as its foreign key. Am attaching my model code below User Model
const Sequelize = require('sequelize');
const sequelize = require('../config');
let Users = sequelize.define('users', {
id : {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
username: {
type: Sequelize.STRING,
},
password: {
type: Sequelize.STRING
}
});
module.exports = Users;
Products Model
const Sequelize = require('sequelize');
const sequelize = require('../config');
let products=sequelize.define('products', {
id : {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
category : {
type: Sequelize.STRING,
allowNull: false
},
name : {
type: Sequelize.STRING,
allowNull: false
},
price: {
type: Sequelize.INTEGER,
allowNull: false
}
});
module.exports= products;
Orders Model
const Sequelize = require('sequelize');
const sequelize = require('../config');
let users=require('./user');
let products=require('./product');
let orders=sequelize.define('orders', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
user_id: {
type: Sequelize.INTEGER,
references: {
model: 'users',
key: 'id'
}
},
product_id: {
type: Sequelize.INTEGER,
references: {
model: 'products',
key: 'id'
}
},
price: {
type: Sequelize.INTEGER,
allowNull: false
}
});
module.exports= orders;
I want this following raw query to be performed via SEQUELIZE
SELECT * FROM ((orders INNER JOIN users ON users.id=orders.user_id) INNER JOIN products ON products.id=orders.product_id);
I have looked at the documentation but i couldn't figure out how to do it. ANy help is appreciated. Thanks