문제점
Cart에 갯수가 담기지 않는 현상이 발생했다.
시도해본 것
model/cart-item에 들어가서 sequelize.define을 확인
해결
...
const CartItem = sequelize.define('cartItem', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
allowNull: false,
primaryKey: true
},
quantity: Sequelize.INTEGER // 안적혀 있었음
});
...
중간 테이블인 CartItem에 quantity가 빠져있었다.
알게된 점
Cart.belongsToMany(Product, { through: CartItem });
Product.belongsToMany(Cart, { through: CartItem });
Cart와 Product의 중간 테이블인 CartItem을 유의하자