0

I have a many-to-many relationship between my group model and my sport model with the usual group_sport table as the pivot table.

Group table

ID|Group_name
1 |Group 1
2 |Group 2
3 |Group 3

group_sport table

ID|groupID|sportID
1 |1      |1
2 |1      |2
3 |1      |3
4 |2      |2
5 |2      |4
6 |3      |5
7 |3      |6
8 |3      |4

sport table

ID|sport_name
1 |football
2 |tennis
3 |golf
4 |hockey
5 |cricket
6 |athletics

What I would like to do is display all distinct groups with their corresponding sport in the view so it would look something like this

Group 1|football, golf, tennis
Group 2|tennis, hockey
Group 3|cricket, athletics, hockey

I can achieve this by doing 3 separate queries but would there be a more efficient way?

Or what I don't mind doing is displaying all sports and ordering by group but then that means I would be displaying all sports however with their groups(the groups would be repeated which is what I don't want).

In this case would you know if JQuery could help in deleting certain elements so that my groups are not repeated?

Billy
  • 2,823
  • 3
  • 16
  • 33

0 Answers0