Created At
Automatically adds creation timestamps to database records
The withCreatedAt
mixin automatically adds timestamps when records are created in the database. This eliminates the need to manually set created_at fields on every insert operation.
Usage
API Reference
withCreatedAt()
Enhances a model with automatic createdAt timestamp functionality.
Parameters
model
- The base model to enhancefield
- The name of the field to use for creation timestamps (e.g., 'createdAt')
Returns
Enhanced model that automatically sets the creation timestamp field during insert operations.
Features
- Automatic Timestamps: Sets the specified field to the current date/time on insert
- Batch Support: Works with both single and batch insert operations
- Respect Existing Values: Preserves existing timestamp values if already provided
- Composition: Works well with other mixins in combination