Reputation: 502
In actionDelete I have write query for get fk from all table and create activeDataProvider.and write a foreach loop for geting one by one element.
$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();
Now it's work Doing same think for all table one by one
}
return $this->redirect(['index']);
I am troubling with how save this Flag 'Y' in all table where this practiceCode as foreign key.Please help how to do....Thanks in advance
Upvotes: 1
Views: 1022
Reputation: 436
i.e : $oModel = ModelName::find()->with('originaltable_name')->where(['practiceCode' => $your_value])->all();
you will select your records and delete. you will define your relation using with()
Upvotes: 2