I have several tables which I want to retrieve data from using sequelize. The schema for these tables appears below:
I want to join three of these tables, but I'm getting error number 1054.
Here is my code:
Skill model:
'use strict';
module.exports=(sequelize,Datatypes)=>{
const Skill=sequelize.define('userskills',{
id:{type:Datatypes.INTEGER,autoincrement:true,primaryKey:true},
Userid:{type:Datatypes.INTEGER,allowNull:false},
Skill:{type:Datatypes.STRING,allowNull:false}
});
Skill.associate=(model)=>{
Skill.belongsTo(model.User,{
as:"User info",
onDelete:"CASCADE",
onUpdate:"CASCADE",
foreignKey: 'Userid',
targetKey:"id"
});
Skill.belongsTo(model.Subcategory,{
as:"Skill info",
onDelete:"CASCADE",
onUpdate:"CASCADE",
foreignKey:"Skillid",
targetKey:"id"
});
};
return Skill;
};
The function called for getting the data :
router.get('/',(req,res)=>{
model.Skill.findAll({
include:[{all:true}]
}).then(result=>{
res.status(200).json({
result
});
}).catch(err=>{
res.status(500).json({
error:err
});
});
});