Delete with ztabularinputmanager

Hi, it seems that a delete method is not implemented with the extension ztabularinputmanager:

http://www.yiiframework.com/extension/ztabularinputmanager

What code should be added to delete a "father/master" model and all its "children/detail" models as well?

Any help will be appreciated.

ok I got it working and I will share my solution here so if the author zaccaria or anyone else has a better/safer way to do it, please let us know here.

add in TabularInputManager.php (the author may consider to add this in the extension package):




/**

 * Delete all the items that belongs to the model specified by primary key

 * @param model the model on wich the items belongs to

 */

public abstract function deleteAllItems($modelPk);



Now, following the names of the examples in the extension page:

add in class StudentManager:




    public function deleteAllItems($modelPk)

   {

        Student::model()->deleteAllByAttributes(array('class_id'=>$modelPk));

    }



and your controller actionDelete code may look like this:


	/**

	 * Deletes a particular model.

	 * If deletion is successful, the browser will be redirected to the 'admin' page.

	 * @param integer $id the ID of the model to be deleted

	 */

	public function actionDelete($id)

	{

		if(Yii::app()->request->isPostRequest)

		{

			// we only allow deletion via POST request

			$model=$this->loadModel($id);

                        $studentManager=StudentManager::load($model);

                        

                        $studentManager->deleteAllItems($model->primaryKey);

                        $model->delete();


			// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser

			if(!isset($_GET['ajax']))

				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));

		}

		else

			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');

	}



Hope this helps.

Changed this:




    public function deleteAllItems($modelPk)

   {

        $criteria=new CDbCriteria;

        $criteria->addCondition("class_id = {$modelPk}");

 

        Student::model()->deleteAll($criteria); 

    }



to this:




    public function deleteAllItems($modelPk)

   {

        Student::model()->deleteAllByAttributes(array('class_id'=>$modelPk));

    }



Just to simplify a bit.