Can I Use $This->Id In Model's Afterfind() Function?

Hi All

I have two models one is Orders and one is Budgets.

I want to calculate remaining amount for a Budget category afterFind on the Budget model.

Can I use $this->id in my expression to calculate the remainding?

The following just causes my page to hang, no errors:




 protected function afterFind ()

    {

        $this->remaining = $this->cat_budget;

        $tmp = Order::model()->findAll('catid=:c1',array(':c1'=>$this->id));

        foreach ($tmp as $val) {

            if (is_numeric($val->total)) {

                $this->remaining -= $val->total;

            }

        }

    }



Any suggestions?

Thanks

Johan

Hi JoeBod

Try




protected function afterFind()

{

   $this->remaining = $this->cat_budget;

        $tmp = Order::model()->findAll('catid=:c1',array(':c1'=>$this->id));

        foreach ($tmp as $val) {

            if (is_numeric($val->total)) {

                $this->remaining -= $val->total;

            }

        }

  parent::afterFind();//ADD THIS

}



Hi BlkRaven

Thanks for reply, I changed my code to calculate it in the controller with an Ajax request.

Out of interest I tried adding the parent::afterFind(); but that didn’t make a difference.

The page still hung and timed out after a while.

Thanks anyway

Regards

Joe