Skip to main content

create simple sequelize model



isFree: { type:DataTypes.BOOLEAN, validate: { isUnique: function(value, cb){ console.log(this._previousDataValues) if (this._previousDataValues.isFree == true){ throw new Error ('You must keep your promise to treat everyone') } else { cb() } } } hooks: { beforeBulkDestroy: (user, options, cb) => { if (user.where.participants > 0){ throw new Error (`Sorry, event, ${user.where.participants} people already confirmed to come`) } else { cb() } } } Schedule.prototype.getAvailableSeat = () =>{ let result = this.maxParticipants - this.participants return result };


Let’s instead create a function that accepts an object category and an array of object products. We want this function to create a new row in the categories table in our PostgreSQL database with the new category object, while also creating new rows in the products table for each product object in the product array. Of course, this method should be called when every product in the array corresponds to the category object that is being passed.


Comments