-
Notifications
You must be signed in to change notification settings - Fork 1
Timestamps
Radosław Mejer edited this page May 9, 2020
·
1 revision
Timestamps are datetime
columns which contain the information about:
- models creation date (by default:
created_at
) - models update date (by default:
updated_at
)
When enabled, the plugin will hook into update()
and insert()
methods and set the corresponding fields.
const User = kex.createModel('User', {
timestamps: true
})
await User.create({ name: 'Jon' }) // will set the `created_at` and `updated_at` to current date
await User.query()
.where('id', 1)
.update({ active: false }) // will set the `updated_at` to current date
You may change the names of the columns by passing an object with options:
const User = kex.createModel('User', {
timestamps: {
createdAtColumn: 'createdAt',
updatedAtColumn: 'updatedAt'
}
})