I am trying to get 2 left outer join from sequelize by using nested include. But, second include inside 1st include is not returning table's data.
call.hasMany(session,{
as: "sessions"
})
session.belongsTo(call,{
foreignKey: "call_id",
as: "call"
})
session.hasMany(session_extra_data,{
as: "sessionExtraData"
})
session_extra_data.belongsTo(session,{
foreignKey: "session_id",
as: "session"
})
call.findAll({
limit: 5,
include: [{
model: session,
as: "sessions",
indlude:[{
model: session_extra_data,
as: "sessionExtraData",
}],
required: false
}],
}).then(data => {
console.log("DATA", JSON.stringify(data));
})
call model
const call = sequelize.define('call', {
id: {
type: Sequelize.BIGINT,
allowNull: false,
primaryKey: true,
autoIncrement: true,
field: 'id'
},
version: {
allowNull: false,
type: Sequelize.BIGINT,
field: 'version'
},
},{
freezeTableName:true,
timestamps: false
});
Session model
const session = sequelize.define('session', {
id: {
type: Sequelize.BIGINT,
allowNull: false,
primaryKey: true,
autoIncrement: true,
field: 'id'
},
version: {
field: 'version',
type: Sequelize.BIGINT,
allowNull: false,
},
callId : {
field: 'call_id',
type: Sequelize.BIGINT,
allowNull: false
},
},{
freezeTableName:true,
timestamps: false
});
session extra model
const session_extra_data = sequelize.define('session_extra_data', {
id: {
type: Sequelize.BIGINT,
allowNull: false,
primaryKey: true,
autoIncrement: true,
field: 'id'
},
version: {
field: 'version',
type: Sequelize.BIGINT,
allowNull: false,
},
tenantId: {
field: 'tenant_id',
type: Sequelize.STRING(255),
allowNull: false,
},
sessionId : {
field: 'session_id',
type: Sequelize.BIGINT,
allowNull: false
},
},{
freezeTableName:true,
timestamps: false
});
I have put all the model definition in code. you can see and tell me what i am doing wrong.
there is foreign key in session table data of call id as call_id there is foreign key in session-extra-data table data of Session id as session_id