Skip to content

Commit

Permalink
craete image model
Browse files Browse the repository at this point in the history
  • Loading branch information
Atallah0 committed Nov 4, 2023
1 parent e8b2860 commit 41c0134
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions models/imagesModle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const DataTypes = require('sequelize');
const sequelize = require('../utils/dataBaseConnection');
const Product = require('./productModel');

const Image = sequelize.define('image', {
id: {
type: DataTypes.INTEGER(15),
allowNull: false,
autoIncrement: true,
primaryKey: true
},
imageUrl: {
type: DataTypes.STRING(255),
allowNull: false,
validate: {
notEmpty: {
msg: 'Image URL cannot be empty',
},
isURL: {
msg: 'Invalid URL format',
},
},
},
productId: {
type: DataTypes.INTEGER(15),
allowNull: false,
references: {
model: Product,
key: 'id',
onDelete: 'CASCADE',
},
},
}, {
freezeTableName: true,
timestamps: false,
});

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


module.exports = Image;

0 comments on commit 41c0134

Please sign in to comment.