I'm trying to use TimestampBehavior in my Restful API created Yii2, but when I create a new entity using the POST endpoint, the return data is quite strange.
{
"i18_id": 3,
"language": "es",
"text": "un test de traducción",
"created_at": {
"expression": "NOW()",
"params": [ ]
},
"updated_at": {
"expression": "NOW()",
"params": [ ]
},
"id": 2
}
When I GET the entity later everything looks fine.
Here is how I've declared the Behavior in my model:
public function behaviors()
{
return [
'timestamp' => [
'class' => 'yii\behaviors\TimestampBehavior',
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
],
'value' => new Expression('NOW()'),
],
];
}