I got a model call Answer, and here is its table
id group_id qset_id
1 123 1
2 123 2
3 123 1
4 456 1
5 456 1
6 456 3
I need to return a array or json format include every group_id and their different qset_id
Maybe like this
class: [
{
"group_id": 123
"qset_id": [1,2]
},
{
"group_id": 456
"qset_id": [1,3]
}
]
I thought about group_by, but I am stuck here. And the table is very large, is there a efficient Rails way to handle that?