/** * Deletes an existing Blog model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $model = $this->findModel($id); foreach (BlogTag::find()->where(['blog_id' => $model->id])->with('tag')->all() as $removedItem) { $removedItem->tag->frequency--; $removedItem->tag->save(); $removedItem->delete(); } $model->delete(); return $this->redirect(['index']); }
/** * @return \yii\db\ActiveQuery */ public function getBlogTag() { return $this->hasOne(BlogTag::className(), ['blog_id' => 'id']); }