Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Many to many relationship react-admin

Im trying to show in a Datagrid a Field that is in a many to many relationship (intermediate table).

I have these tables:

group - group_subject - subject

  • A group can have many subjects
  • A subject can be connected with many Groups

group_subject also has attributes like rubrics and schedule

It's a many to many relationship. I would like to show in the <Resource> group all the subjects that a group is connected to.

Using something like the <SingleFieldList>: as this image

I'm using react-admin. Is there a way to get values in this relationship?

like image 995
oskrgg Avatar asked Nov 08 '22 06:11

oskrgg


1 Answers

The easiest way would be to hide that intermediate table from react-admin. It's a good thing to hide this implementation detail anyway IMO. Users of your API shouldn't be aware of it.

  • from the groups resource perspective, a group has many subjects, each subject having a group_id and you API should allow to retrieve subjects by this group_id field

  • from the subjects resource perspective, a subject has many groups, each group having a subject_id and you API should allow to retrieve groups by this subject_id field

like image 126
Gildas Garcia Avatar answered Dec 10 '22 05:12

Gildas Garcia