Hi Guys!
I just realized a strange problem with TimestampBehaviour in my models.
The situation:
[list=1]
[*]When I create a new record both timestamps are set correctly.
[*]When I update an existing record "updated_at" is set correctly but "created_at" gets destroyed and has a strange (random) value like: 1, 20 or 22…
[/list]
So far I was not able to figure out why this happens.
My configuration / implementation:
I use mySQL with InnoDB.
The timestamp fields are setup like this:
created_at => int(11)
updated_at => int(11)
My implementation of timstamp behavior in model:
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
... ... ...
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
],
],
];
}
Like I said this only happens on created_at field when I want to update a record.
The updated_at field is updated corretly to current timestamp.
On new created records both timestamps are set correctly.
Any Ideas why this happens?
Thanks and best regards