Answer the question
In order to leave comments, you need to log in
How to update a record without changing updated_at in Yii2?
It was required in one specific case, when changing the model, do not change updated_at.
public function behaviors()
{
return [
'timestamp' => [
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
],
],
]
}
public function actionUpdate($id)
{
$model = $this->findModel($id);
$model->scenario = Model::SCENARIO_UPDATE_STATUS;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['/models']);
}
return $this->render('update', [
'model' => $model,
]);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question