Asked
Active
Viewed 103 times
-2
-
Please show piece of code where you are getting error and describe problem. so that community could help you in efficient way. – mabc224 Oct 21 '19 at 10:41
-
Unhandled rejection TypeError: Cannot read property 'map' of undefined – tejashri bhingare Oct 21 '19 at 10:49
-
[https://github.com/tejashridbk/tejashri/blob/master/api/routes/index.js] in this file i have error – tejashri bhingare Oct 21 '19 at 10:52
-
You have 5 `map` usage in this file. Please, write full error (in generally you also should get in which line of code you got this error). – Dmytro Mysak Oct 21 '19 at 12:49
2 Answers
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 }
});
}