/** * Deletes an existing MappingQuestions model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id, $cat_id) { $this->findModel($id)->delete(); MappingQuestionsToOptions::deleteAll(['question_id' => $id]); return $this->redirect(['mapping-categories/view', 'id' => $cat_id]); }
/** * Deletes an existing MappingCategories model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { foreach (MappingQuestions::find()->where(['category_id' => $id])->all() as $question) { MappingQuestionsToOptions::deleteAll(['question_id' => $question->id]); $question->delete(); } $this->findModel($id)->delete(); return $this->redirect(['index']); }