Boolean vs Timestamp
vercotux opened this issue · 4 comments
Would it not make sense to use a unix timestamp to indicate deletion as opposed to a simple boolean?
It is certainly important to know when a record was deleted, not just whether it was. It could both be done with one column by storing unix timestamps instead of booleans. A set value means that the record was deleted AND it also tells you when. The column being NULL means the record has not been deleted. Furthermore this could be done consistently with TimestampBehavior by calling the attribute "deleted_at".
The only (and perhaps negligible) downside is the possibility of slightly higher storage requirement (using INT instead of BIT).
At the very least this could be a configurable option of SoftDelete.
You mau achieve this using yii\db\Expression
in softDeleteAttributeValues
:
'softDeleteAttributeValues' => [
'deletedAt' => new Expression('NOW()')
],
Would make sense to be the default, but I'm glad there's a simple way to do it. Thanks.
Since you are at it, could you call it "deleted_at" instead of deletedAt, to make it more consistent with Yii2's TimestampBehavior defaults for $createdAtAttribute and $updatedAtAttribute so that we end up with three:
- created_at
- updated_at
- deleted_at