ruby - Rails nested group and count with column renaming -
i have model looks way:
issue(id, ..., tracker_id) | tracker(id, ..., name)
issue has_one :tracker tracker has_many :issues
and number of issues per tracker. have got is:
issue.group(:tracker_id).count => {3=>446, 5=>247, 9=>2, 11=>560}
but instead of grouping tracker_id
, group tracker_name
, this:
{"name_1"=>446, "name_2"=>247, "name_3"=>2, "another_name"=>560}
is there way directly, without mapping operation / hash renaming ?
there way:
issue.joins(:tracker).group('trackers.name').count
Comments
Post a Comment