php - kohana orm top user -


i have 2 tables

the users , comments

the comments have many 1 relationship users

trying think of way using orm top users based on amount of comments

any suggestions?

your query should this:

select users.username, count(comments.id) total  users  inner join comments  on users.id = comments.user_id  group users.username  order count(comments.id) desc 

translated orm:

orm::factory('user')    ->select('user.username', array('count("comments.id")', 'total'))    ->join('comments', 'inner')    ->on('user.id', '=', 'comments.user_id')    ->group_by('user.username')    ->order_by('total', 'desc')    ->find_all(); 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -