So I can disable the timestamp columns for a particular model but is there a way to disable it for all models?
const Contract = sequelize.define('Contract', {
idContract: {
type: Sequelize.INTEGER,
primaryKey: true
},
AccountNo_Lender: {
type: Sequelize.STRING
}
}, { timestamps: false });
You either have to declare public $timestamps = false; in every model, or create a BaseModel, define it there, and have all your models extend it instead of eloquent. Just bare in mind pivot tables MUST have timestamps if you're using Eloquent.
If you don't want the columns, you need to set the timestamps option as false when you define your model: const User = sequelize. define( "User", { firstName: Sequelize. STRING }, { timestamps: false } );
You can define this when initializing the sequelize
object.
const sequelize = new Sequelize('test', 'postgres', 'postgres', {
host: '127.0.0.1',
dialect: 'postgres',
define: {
timestamps: false
},
});
Options under define
are as same as when we define them inside the model. So all the options which can be used inside the model can be used here as well. From the docs
// Specify options, which are used when sequelize.define is called.
// The following example: // define: { timestamps: false } // is basically the same as: // sequelize.define(name, attributes, { timestamps: false }) // so defining the timestamps for each model will be not necessary
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With