在 actionDelete 中,我为所有表中的get fk编写了查询,并创建了activeDataProvider。并编写了一个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();
现在它的工作一个一个地为所有表做同样的思考
}
return $this->redirect(['index']);
我很担心如何拯救这个国旗' Y'在所有表中,这个 practiceCode 作为外键。请帮忙怎么做....提前致谢
答案 0 :(得分:2)
即:$oModel = ModelName::find()->with('originaltable_name')->where(['practiceCode' => $your_value])->all();
您将选择您的记录并删除。您将使用with()