Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Boolean vs Timestamp #1

Closed
vercotux opened this issue Aug 15, 2015 · 4 comments
Closed

Boolean vs Timestamp #1

vercotux opened this issue Aug 15, 2015 · 4 comments

Comments

@vercotux
Copy link

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.

@klimov-paul
Copy link
Member

You mau achieve this using yii\db\Expression in softDeleteAttributeValues:

'softDeleteAttributeValues' => [
    'deletedAt' => new Expression('NOW()')
],

@vercotux
Copy link
Author

Would make sense to be the default, but I'm glad there's a simple way to do it. Thanks.

@klimov-paul
Copy link
Member

d62def6

@vercotux
Copy link
Author

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

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

No branches or pull requests

2 participants