sequelize-auto icon indicating copy to clipboard operation
sequelize-auto copied to clipboard

Add option to create instance instead of automatically returning the definition of the model

Open Xoouu opened this issue 2 years ago • 0 comments

Instead of defining the model like this:

module.exports = function(sequelize, DataTypes) {
  return sequelize.define('User', {
    // Model attributes are defined here
    firstName: {
      type: DataTypes.STRING,
      allowNull: false
    },
    lastName: {
      type: DataTypes.STRING
      // allowNull defaults to true
    },
  }
}

Being able to choose to define it with an instance:

module.exports = function(sequelize, DataTypes) {
  const User = sequelize.define('User', {
    // Model attributes are defined here
    firstName: {
      type: DataTypes.STRING,
      allowNull: false
    },
    lastName: {
      type: DataTypes.STRING
      // allowNull defaults to true
    }
  }, {
    // Other model options go here
  });

  // Hook
  User.beforeCreate(()=>{
   // something
  })
  
  return User;
}

If that is possible to already do, where can I find that information?

Xoouu avatar Dec 01 '22 18:12 Xoouu