A
A
AlexAll2020-01-25 16:34:35
Yii
AlexAll, 2020-01-25 16:34:35

What is the best way to add the date of adding and editing to the database from yii2 for speed, database trigger or behavior?

In yii2 there is a behavior with which the date is added to the database when a post is saved or updated.
But you can use mysql or postgresql database triggers to add dates to the required fields during insert or update
. Does it make sense to use triggers and is there an increase from this, or maybe vice versa?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2020-01-25
@AlexAll

Does it make sense to use triggers and is there an increase from this, or maybe vice versa?

Why do you need to move the logic of adding the date somewhere?
For example, you updated the counter of views - you have updated the update date. Although logically it should change when some important information (content) is updated. If you display this date on the page, then there will be problems. You only updated the content view count, but did not change the content. Such a date misinforms users. Any time the user views it, the date will be updated.
I would recommend building the logic in such a way that you manage dates at the business logic level. If this is the creation date, then you pass the date when the entity was created. If this is the update date, then when the content changes.
A small example. There is a blog. With fields: title, update date, views. You update the visit counter - the date is updated. It's not logical. The date should change when the content is updated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question