Sending categoryID from postman, but unable to save in Product table.
/
/ Products Schema
module.exports=(sequelize,DataTypes)=>{
let Products = sequelize.define('Products',{
productName : DataTypes.STRING,
unit : DataTypes.STRING,
price : DataTypes.STRING,
});
Products.associate = function(models){
Products.hasMany(models.Categories,{
foreignKey : 'id',
as : 'categoryID'
});
Products.hasMany(models.Suppliers,{
foreignKey : 'id',
as : 'supplierID'
});
}
return Products;
}
Product Controller
const productCollection = await Product.create({
productName: req.body.productName,
unit: req.body.unit,
price: req.body.price,
categoryID: req.body.categoryID,
})
res.status(200).send(productCollection)
Executing (default): INSERT INTO "Products" ("id","productName","unit","price","createdAt","updatedAt") VALUES (DEFAULT,$1,$2,$3,$4,$5);
Although I have Check in Product Table , categoryID Column exist there. Foreign key is added in Product Table using migration categoryID:{ .... references:{....}}