Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Xoouu opened this issue Dec 1, 2022 · 0 comments

Comments

@Xoouu
Copy link

Xoouu commented Dec 1, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant