1

My issue is related to the query,

I want to get all the products with it's related category.

And a product can have multiple Category

My Product table is

IdProduct: {
      primaryKey: true,
      type: Sequelize.INTEGER,
      allowNull: false,
      autoIncrement: true,
    },
    CommodityClass: {
      type: Sequelize.INTEGER,
      allowNull: false,
    }

My Category Table is

IdProductCategory: {
        primaryKey: true,
        type: Sequelize.INTEGER,
        allowNull: false,
        autoIncrement: true
    },
    Name: {
        type: Sequelize.STRING,
        allowNull: false
    }

and my productcategoryproduct table is (It contains the id of product and category)

IdProductCategory: {
    type: Sequelize.INTEGER,
    primaryKey: true,
    allowNull: false,
    references: {
        model: 'ProductCategory',
        key: 'IdProductCategory',
    }
},
IdProduct: {
    type: Sequelize.INTEGER,
    primaryKey: true,
    allowNull: false,
    references: {
        model: 'Product',
        key: 'IdProduct',
    }
}

I have used association as

Product.hasMany(ProductCategoryProduct);

// Product Association
ProductCategoryProduct.belongsTo(Product, { foreignKey: 'IdProduct'});

My query is

Product.findAll({
  include: {
     all: true
  }
 })
 .then((results) => {
      ...
  })

But I'm getting the error

"message":"Invalid column name 'productIdProduct'

Can someone please help me in this?

jarlh
  • 42,561
  • 8
  • 45
  • 63
Rupesh
  • 850
  • 2
  • 13
  • 30

0 Answers0