-1

I need to apply group on associated attributes to apply it on pie_chart which is the method of kick chart so I just need to fetch the associated object attribute like

= pie_chart array.group(:user)

it returns the user object but I need to apply group on user attribute which is username so please if anybody has solution of this answer me.

Ali Hassan Mirza
  • 552
  • 11
  • 23
  • Could you provide some more code to make it more obvious what you are trying to achieve? – Fabian Winkler Nov 25 '15 at 12:00
  • I am using kickchart and in kick chart I want to use pie_chart and for that I need to show the chart with the username of every object which is linker and linker is associated with user one linker can be create a user. and I am fetching the linkers array and by this array I need to apply every linker to its user and then the username hopefully you understand now – Ali Hassan Mirza Nov 25 '15 at 12:06

1 Answers1

0

You can use Enumerable#group_by (http://ruby-doc.org/core-2.2.3/Enumerable.html#method-i-group_by)

Example :

array.group_by { |linker| linker.user.username }

It will create a Hash with the usernames as keys and Array of linkers as values

Holin
  • 1,191
  • 10
  • 10