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
Post a Comment