@
@
@Insout2017-01-07 19:23:11
Yii
@Insout, 2017-01-07 19:23:11

Why doesn't timestampBehavior yii2 work correctly?

Hello.
Why doesn't timestampBehavior work correctly?
In the model

public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],
        ];
    }

The fields in the table are called created_at and updated_at (timestamp field type).
Actions are created by CRUD generator.
The resulting result is:
1. When the record is created - both fields get 0000-00-00 00:00:00
2. When the record is updated, the created_at field gets the date and time of the update, the updated_at field remains 0000-00-00 00:00:00
What did I do wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Decadal, 2017-01-07
@Decadal

The yii2 documentation has these lines:
Documentation
try changing the field types. In addition, there is also an example implementation of timestampBehavior.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question