I have a task model related to activities and i want to get a array/hash with all Tasks and their related activities like this:
<% task_group =[
['Task1', {'Activity1' => 1, 'Activity2' => 2}],
['Task2', {'Activity3' => 3, 'Activity4'=> 4}]
] %>
I came up with Task.includes(:activities).all.map(&:name) but this only gives me a list with activities and their name.
How can i get a complete list including nested relations?
My model defintion:
class Task < ActiveRecord::Base
has_many :activities
class Activity < ActiveRecord::Base
belongs_to :task
you can use:
EDIT: