Reputation: 35
I am programming a ConsoleController command for edit some values in some Databases. The problem is when I try to save the Model.
//console/controllers/ConsoleController.php
public function actionChangeCourseTitle()
{
$model = Course::find->where([ 'id' => $id])->all();
$model->title = "new title";
$model->detachBehaviors(); //for deactivate the TimestampBehavior
$model->save();
}
I want to deactivate the automatic save of the timestamp in the field "update_at", with the $model->detachBehaviors() as explained in the yii2 documentation (https://www.yiiframework.com/doc/guide/2.0/en/concept-behaviors#detaching-behaviors). But does not works.
Do you have any idea why does not works? am I defining wrong the detachBehaviors()?
Best Regards,
Paul
Update: it was edited in the SQL Definition of the table.
CREATE TABLE course
(
...
updated_at
datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
... )
I solve the problem with ALTER COLUMN as SQL Query...
ALTER TABLE course
MODIFY COLUMN updated_at
datetime NOT NULL DEFAULT CURRENT_TIMESTAMP;
and I could edit the fields without updating automaticly the field "update_at".
Upvotes: 0
Views: 223
Reputation: 35
Update: it was edited in the SQL Definition of the table.
CREATE TABLE course ( ...
updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
... )
I solve the problem with ALTER COLUMN as SQL Query...
ALTER TABLE course MODIFY COLUMN updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP;
and I could edit the fields without updating automaticly the field "update_at".
Upvotes: 0