{"id":1122,"url":"https://forum.supero.dev/t/modelling-a-many-to-many-relation-students-and-courses-1122","title":"Modelling a many-to-many relation (students and courses)","type":"question","status":"solved","category":{"slug":"architecture","name":"Architecture & Patterns"},"tags":["data-model","how-to"],"author":{"handle":"supero-support","name":"Supero Support","team":true},"created":"2026-12-04T02:40:53.705Z","updated":"2026-12-04T02:40:53.705Z","upvotes":0,"error_text":null,"environment":{"client":null,"sdk_version":null,"deploy_target":null},"body_markdown":"A student takes many courses and a course has many students. In Postgres we'd have an enrolment join table. Should the student schema get a `course_uuids` array field?","answers":[{"id":"1976bc82-37ba-405d-83fc-44e204af8b4e","url":"https://forum.supero.dev/t/modelling-a-many-to-many-relation-students-and-courses-1122#post-1976bc82-37ba-405d-83fc-44e204af8b4e","author":{"handle":"supero-platform","name":"Supero Platform team","team":true},"accepted":true,"official":false,"outdated":false,"sdk_version":null,"upvotes":0,"created":"2026-12-04T02:40:53.705Z","updated":"2026-12-04T02:40:53.705Z","body_markdown":"Don't add uuid fields to express a relationship. Declare it in `references[]` on one side with cardinality `many` and a reverse name:\n\n```json\n\"references\": [\n  {\"name\": \"Course\", \"cardinality\": \"many\", \"back_ref_name\": \"students\"}\n]\n```\n\nThe platform manages the link. Add or remove one edge with `ref-update`, or many at once with `PUT /api/v1/crud/{domain}/ref-update-multi`:\n\n```bash\ncurl -X PUT https://api.supero.dev/api/v1/crud/acme/ref-update \\\n  -H \"Authorization: Bearer $ACCESS_TOKEN\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"type\": \"student\", \"uuid\": \"<student-uuid>\", \"ref-type\": \"course\", \"ref-uuid\": \"<course-uuid>\", \"operation\": \"ADD\"}'\n```\n\nRead a student's courses with `GET /api/v1/crud/{domain}/student/{uuid}/refs/course`. For the other direction, `GET /api/v1/crud/{domain}/course/{uuid}/back-refs` returns the records that point at that course, and `/list-bulk` takes `back_ref_id` for the same thing in a list call.\n\nAdding a reference needs create-or-update permission on the source type and read on the target, so check the student role's policy if ADD is refused. If the enrolment carries its own data, such as a grade or a start date, make it a schema of its own with a `one` reference to Student and a `one` reference to Course.","comments":[]}],"licence":"CC BY-SA 4.0 (code: MIT-0)"}