I have a table menu and a "child" table rssold that has a related field mn_id with menu.id
So I want when a menu item is deleted to delete all rssold related data
So at menu model I have this code that it does not seem to work,how can I solve it?
public function beforeDelete()
{
if (parent::beforeDelete()) {
Yii::$app->db->createCommand('delete from rssold where mn_id=:id')
->bindParam(':id', $this->id )
->execute();
return true;
} else {
return false;
}
}
Also the controller code
public function actionDeletecat($param) {
if ($param == null || !is_numeric($param)) {
throw new \yii\web\HttpException(404, 'The requested Item could not be found.');
die();
}
$model = \app\models\Menu::find()->where(['id' => $param])->one();
Yii::$app->db->createCommand('delete from menu where id=:id')
->bindParam(':id',$param )
->execute();
$this->redirect(Url::to(['manager/cats', 'param' => $model['type']]), 302);
}