When SUMing a Column in AR, how do you access it's value?


$links = Link::model()->with(‘votes’)->findAll(array(

'select' => 'SUM(karma_delta) AS karma',

'condition' => 'links.id = votes.link_id',

'group' => 'votes.link_id',

'order' => '(SUM(votes.karma_delta) - 1) / POW((TIMESTAMPDIFF(HOUR, links.created, NOW()) + 2), 1.5) DESC',



How do I access karma in my views? They don’t seem to show up when I print_r my $links variable.

Took me a while but I figured it out! Just had to add

public $karma;

to my model and all was good.

You could also define a statistical relation, see http://www.yiiframework.com/doc/guide/database.arr