with(['educations'])->all() as $app) { $app_specialities = BachelorSpeciality::find()->where(['application_id' => $app->id])->all(); foreach ($app_specialities as $bachelor_spec) { if (EmptyCheck::isEmpty($bachelor_spec->education_id)) { $bachelor_spec->education_id = ArrayHelper::getValue($app, 'educations.0.id'); $bachelor_spec->save(true, ['education_id']); } } } } public function safeDown() { BachelorSpeciality::updateAll(['education_id' => null]); } }