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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -