UNPKG

swagelize

Version:

Generate Sequelize model definitions and DAO from a Swagger 2.0 schema

32 lines (27 loc) 793 B
module.exports = function(sequelize, DataTypes) { var Pet = sequelize.define('Pet', { id: { type: DataTypes.BIGINT, format: 'int64', allowNull: false, primaryKey: true, autoIncrement: true }, name: { type: DataTypes.STRING, example: 'doggie', allowNull: true }, status: { type: DataTypes.ENUM('available', 'pending', 'sold'), description: 'pet status in the store', allowNull: true } }, { tableName: 'Pet', timestamps: false }); Pet.associate = function (models) { models.Pet.belongsToMany(models.Tag, {as: 'tags',through: {model:models.PetTag, unique:false},foreignKey: 'id_pet',otherKey: 'id_tag'}); models.Pet.belongsTo(models.Category, { onDelete:'CASCADE', foreignKey: 'id_category' }); }; return Pet; };