Custom SQL attribute won't use model primary key

Hi,

I have a custom attribute in my model which is getting the total cost for an order.

My method code is pretty simple:




public function getTotals(){

	$sql = "SELECT SUM(price) as 'sum' FROM event_order_product WHERE order_id = " . $this->id . " GROUP BY order_id";

	$sum = Yii::app()->db->createCommand($sql)->queryScalar();

	return $sum;

}



The problem i’m running into is that when i use $this->id in the mysql query i get Mysql errors because there is nothing where the id should be.

If i return $this->id it will return the id fine. But not in the mysql.

Any idea why this would be acting like this?

Thanks

Oliver

I figured it out. I had filtering enabled which was messing up the first query. Just disabled filtering on my CGridview column and it worked like a charm.

Thanks

Oliver