]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Удаление потомков
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 8 Sep 2025 06:29:17 +0000 (09:29 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 8 Sep 2025 06:29:17 +0000 (09:29 +0300)
erp24/controllers/MatrixTypeController.php

index 582902af2773244db955b0474f3a1807326586e8..c1ebd6295fe84be1daecee233bf7f7ef2515bf36 100644 (file)
@@ -146,11 +146,23 @@ class MatrixTypeController extends Controller
      */
     public function actionDelete($id)
     {
-        $this->findModel($id)->delete();
+        $model = $this->findModel($id);
+        $this->deleteWithChildren($model);
 
         return $this->redirect(['index']);
     }
 
+    protected function deleteWithChildren($model)
+    {
+        $children = $model::find()->where(['parent_id' => $model->id])->all();
+
+        foreach ($children as $child) {
+            $this->deleteWithChildren($child);
+        }
+
+        $model->delete();
+    }
+
     /**
      * Finds the MatrixType model based on its primary key value.
      * @param int $id