title: Yii - using afterDelete() to update data in another table
body: <p>I am using Yii afterdelete() to update the related data which is deleted in another table. Here is my code in the controller:</p>
  
  <p><strong>Controller Action</strong></p>
  
  <pre><code>public function actionDelete($id)
  {
      if(Yii::app()-&gt;request-&gt;isPostRequest)
      {
          // we only allow deletion via POST request
          $this-&gt;loadModel($id)-&gt;delete();
  
          // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
          if(!isset($_GET['ajax']))
              $this-&gt;redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
      }
      else
          throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
  }
  </code></pre>
  
  <p><strong>Model function</strong>       </p>
  
  <pre><code>  protected function afterDelete()
     {
          parent::afterDelete();
          $show_model = new Show();
          $show_model = Show::model()-&gt;findAll('tbl_season_id='.$this-&gt;id);
          $show_model-&gt;updateAll('tbl_season_id = NULL, on_season=0');
  
     }
  </code></pre>