public function beforeDelete($event) { $oldId = $this->owner->{$this->savedAttribute}; if (($oldModel = FileModel::findOne($oldId)) !== null) { $event->isValid = $event->isValid && $oldModel->delete(); } }