$t = \Db::select(\Db::expr('COUNT(comm_id) AS count_result'), 'comm_parent_id') ->from('cms_comments') ->and_where('comm_type', '=', 'blog') ->and_where('comm_parent_id', 'in', $ids) ->group_by('comm_parent_id') ->execute()->as_array();
$t = \Cms\Model_Comment::query() ->select(\Db::expr('COUNT(comm_id) AS count_result'), 'comm_parent_id') // Db::expr() works badly ->where(array( array('comm_type', '=', 'blog'), array('comm_parent_id', 'in', $ids), )) //->group_by('comm_parent_id') // No group_by() method ->get();
$t = \Cms\Model_Comment::query() ->select(array(\Db::expr('COUNT(comm_id)'), 'count_result'), 'comm_parent_id')
Fuel\Core\Database_Exception Object ( [message:protected] => Unknown column 't0.COUNT(comm_id)' in 'field list' [ SELECT `t0`.`COUNT(comm_id)` AS `t0_c0`, `t0`.`comm_parent_id` AS `t0_c1` FROM `cms_comments` AS `t0` WHERE `t0`.`comm_type` = 'blog' AND `t0`.`comm_parent_id` IN ('19', '18', '17', '15', '14', '13', '12', '11', '9', '10', '7', '6', '5', '2', '4', '1', '3') ]
->from('cms_comments')in raw. I just put
->from(call_user_func('\Cms\Model_Comment::table'))to link it with the model. Works fine.
It looks like you're new here. If you want to get involved, click one of these buttons!