Reputation: 55
I have two tables table1 and table2 and I am trying to delete row in these two table.I have same values on both table but id is different so i tried like this, my controller,
public function actionDelete($id)
{
$this->findModel($id);
$select = Employee::find()
->select('Name')
->where(['Id' => $id])
->all();
$deluser=Employee::find()->where(['Id' => $id])->one()->delete() AND User::find()->where(['Name' =>$select])->one();
$deluser->delete();
return $this->redirect(['index','select'=>$select]);
}
pls anyone help me Thanks in advance
Upvotes: 1
Views: 1578
Reputation: 9652
Employee class is object.
Try this:
public function actionDelete($id)
{
$this->findModel($id);
$select = Employee::find()
->select('Name')
->where(['Id' => $id])
->all();
Employee::find()->where(['id' => $id])->one()->delete();
User::find()->where(['id' =>$id])->one()->delete();
return $this->redirect(['index','select'=>$select]);
}
Upvotes: 3