Yii Framework Forum: When SUMing a Column in AR, how do you access it's value? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   thelizardking 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 04-February 09

Posted 22 November 2009 - 03:27 AM

[code]
$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',
));
[code]

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

#2 User is offline   thelizardking 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 04-February 09

Posted 22 November 2009 - 05:00 AM

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

public $karma;


to my model and all was good.
0

#3 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 23 November 2009 - 03:57 AM

You could also define a statistical relation, see http://www.yiiframew...de/database.arr
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users