-2

here is link of my code . I am getting error in index.js in api-routes-index.js. getting error undefined map function

2 Answers2

0

I guess here you have an error:

subcategories: products.subcategories.map(Subcategory => {

products is array, you can't get subcategories from array. Change it to this code:

subcategories: Product.subcategories.map(Subcategory => {

Dmytro Mysak
  • 1,206
  • 15
  • 28
0

Many to many associations in sequilize.js This will be helpful for you to solve the issue:

One product has many order

One order has many product

As a result of many to many we have junction table "orderproduct" which contains product_id and order_id.

   //  In product model
    product.belongsToMany(order, {          
                through: 'orderproduct',
                foreignKey: 'product_id'
            });

   // In order model
    order.belongsToMany(product, {          
                through: 'orderproduct',
                foreignKey: 'order_id'
            });

   // In oderproduct model 
        orderproduct.belongsTo(product, {
            foreignKey: { name: 'product_id', allowNull: false }
        });
        
        orderproduct.belongsTo (order, {
            foreignKey: { name: 'order_id', allowNull: false }
        });
    }
Community
  • 1
  • 1
zshan4444
  • 380
  • 3
  • 7