I want to delete data which is related to another table. If click delete link then will be deleted both data ( suppose I have two tables : A and B, B has foreign key to A. If I click one data in A table then will be deleted B data too. Is that make sense) . Can any one help me?
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadA()->delete();
$this->loadB()->delete();
$this->redirect(array('list'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
Here is my delete link in view file: If click "Delete" link then will be delete data from table A and table B if model->id == model2->a_id
<?php echo CHtml::linkButton(‘Delete’,array(
'submit'=>'',
'params'=>array('command'=>'delete','id'=>$model->id),
'confirm'=>"Are you sure to delete Name # {$model->name}?"));
?>
This is delete only table A data, but i need to delete table A and table B data if id and a_id will same.
public function actionDelete()
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
B::model()->deleteAll('a_id=:id',array(':id'=>$_GET[id]);
$this->loadA()->delete();
$this->redirect(array('list'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}