Skip to content

Commit

Permalink
order delete causing item delete fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BahaaAY committed Dec 4, 2023
1 parent 682123a commit 74b1cac
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ app.use("/purchases", expensesRoutes);
Category.hasMany(Item,{onDelete: 'cascade', hooks: true});
Item.belongsTo(Category, );

Order.belongsToMany(Item, { through: OrderItem, onDelete: 'cascade', hooks: true });
Order.belongsToMany(Item, { through: OrderItem, onDelete: 'SET NULL', hooks: true });
Item.belongsToMany(Order, { through: OrderItem, onDelete: 'SET NULL', hooks: true });

Order.hasMany(OrderItem, { onDelete: 'cascade', hooks: true });
Item.hasMany(OrderItem, { onDelete: 'SET NULL', hooks: true });

OrderItem.belongsTo(Order, {foreignKey: 'orderId', targetKey: 'id', onDelete: 'SET NULL', hooks: true});

OrderItem.belongsTo(Item, {foreignKey: 'itemId', targetKey: 'id'});

//Order -> Purchase
Expand Down

0 comments on commit 74b1cac

Please sign in to comment.