Skip to content

Commit

Permalink
Update wishListItemModel.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanna-Hinn committed Nov 10, 2023
1 parent 09dc71a commit 8499b66
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions models/wishListItemModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,45 @@ const sequelize = require('../utils/dataBaseConnection');
const WishList = require('./wishListModel');
const Product = require('./productModel');

const WishListItem = sequelize.define('wishListItem', {
const WishListItem = sequelize.define(
'wishListItem',
{
id: {
type: DataTypes.INTEGER(15),
allowNull: false,
autoIncrement: true,
primaryKey: true,
}, wishListId: {
type: DataTypes.INTEGER(15),
allowNull: false,
references: {
model: WishList,
key: 'id',
onDelete: 'CASCADE',
},
type: DataTypes.INTEGER(15),
allowNull: false,
autoIncrement: true,
primaryKey: true,
},
wishListId: {
type: DataTypes.INTEGER(15),
allowNull: false,
references: {
model: WishList,
key: 'id',
onDelete: 'CASCADE',
},
},
productId: {
type: DataTypes.INTEGER(15),
allowNull: true,
references: {
model: Product,
key: 'id',
onDelete: 'CASCADE',
},
type: DataTypes.INTEGER(15),
allowNull: true,
references: {
model: Product,
key: 'id',
onDelete: 'CASCADE',
},
},
}, {
},
{
freezeTableName: true,
timestamps: false,
});
}
);

// Associations
WishListItem.belongsTo(WishList, { onDelete: 'cascade', hooks: true }, { foreignKey: 'wishListId' });
WishListItem.belongsTo(WishList, { foreignKey: 'wishListId' });
WishList.hasMany(WishListItem, { foreignKey: 'wishListId' });

WishListItem.belongsTo(Product, /*{ onDelete: 'cascade', hooks: true } ,*/ { foreignKey: 'productId' });
WishListItem.belongsTo(Product, { foreignKey: 'productId' });
Product.hasMany(WishListItem, { foreignKey: 'productId' });


module.exports = WishListItem;

0 comments on commit 8499b66

Please sign in to comment.