如何从 yii2 中的 table 中删除外键约束?

How to delete Foreigen key constraint from table in yii2?

actionDelete 中,我编写了从所有 table 获取 fk 的查询,并创建 activeDataProvider.and 编写一个 foreach 循环以逐个获取元素。

$query = new \yii\db\Query;
        $query->select('practiceCode')->from('member','plan','offer','appointment','product','incentive','clinic','complaint')
        ->where(['practiceCode' => $model->practiceCode])->all();
        $query->createCommand();
        $dataProvider= new ActiveDataProvider([
            'query' => $query,
            'pagination' => false,
       ]);
        $models = $dataProvider->getModels();
        if(count($models) >= 1) {
            $memberModel = new Member();
               foreach ($models as $k) {
                   $k['deleted'] = 'Y';
                  //$memberModel->save();

$connection->createCommand()->update('member', ['deleted' => 'Y'], ['practiceCode' => $models['practiceCode']])->execute();

现在开始了对所有人都做同样的思考table一个一个

            }
        return $this->redirect(['index']);

我很烦恼如何将这个标志 'Y' 保存在所有 table 中 practiceCode as foreign key.Please 帮助如何做。 ...提前致谢

即:$oModel = ModelName::find()->with('originaltable_name')->where(['practiceCode' => $your_value])->all(); 您将 select 您的记录并删除。您将使用 with()

定义您的关系