# Sum and count in find

**URL:** <https://www.ruby-forum.com/t/sum-and-count-in-find/119537>\
**Category:** Rails\
**Created:** [November 7, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/sum-and-count-in-find/119537 "2007-11-07T20:05:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stratboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@stratboy](https://www.ruby-forum.com/u/stratboy)\
**Post date:** [November 7, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/sum-and-count-in-find/119537/1 "2007-11-07T20:05:33Z")

</div>

I have 2 models:

class Core \< ActiveRecord::Base  
has\_many :votes  
has\_many :messages  
end

class Vote \< ActiveRecord::Base  
belongs\_to:core  
end

class Message \< ActiveRecord::Base  
belongs\_to:core  
end

In php for view the last cores names with number of messages and sum of  
votes i do so:

mysql\_query(“SELECT  
name,votes\_join.total\_votes,messages\_join.number\_messages  
FROM core LEFT JOIN (SELECT sum(vote),core\_id FROM votes GROUP BY  
core\_id) as votes\_join on votes\_join.core\_id=core.id LEFT JOIN (SELECT  
count(\*) as number\_messages,core\_id FROM messages GROUP BY core\_id) as  
messages\_join on messages\_join.core\_id=core.id”)

Is possibile di it with find method of models??  
How?  
Thanks
