How to use events to add new data to the database in yii2. There are two related tables, and you need to track the event when an entry is added to one so that we add an entry to the second one.
I try so but something does not work event
And errors:
Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails public function addB() { $model2 = new NameDB(); $tim = round(microtime(true) * 1000); if($this->comment !== null){ $model2->comment = $this->comment; } if($this->userurl_password !== null){ $model2->userurl_password = $this->userurl_password; } Event::on($model2->save(), ActiveRecord::EVENT_AFTER_INSERT, function ($event) { //тут вызываем метод добавления записи в другую таблицу }); }