Answer the question
In order to leave comments, you need to log in
How to force afterSave to save old data that has been changed in 1 plate to another?
Good afternoon. Here I have a Kniga1 plate with my Kniga1.php model. This table has its own fields. Description of the book, etc. I created a second plate so that if you change the description of the book in the first one, it will be saved in the second plate. I already figured out that I need to use the afterSave function.
public function afterSave($insert, $changedAttributes){
parent::afterSave($insert, $changedAttributes);
???
}
But what exactly should I prescribe in order for this connection to work? By the way, I made the usual standard connection between tables. one to many and many to one.
Answer the question
In order to leave comments, you need to log in
For example
public function beforeSave($insert)
{
if (!parent::beforeSave($insert)) {
return false;
}
$description = new Description();
$description->book_id = $this->id;
$description->old_text = $this->text;
$description->created_at = time();
$description->save();
return true;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question