I have a student table and a course table that have a many-to-many relationship (a student can take many courses, and a course can be taken by many students).

If I am implementing the above data model as a database, I would create a third table to represent the many-to-many relationship.

But I want to implement the above data model in Drupal 8. I think that in Drupal 8 there are two ways to implement the above data model:

  • I can create a reference field in one of the two content types (student or course) that points to the other content type.
  • I can create a third content type that have two reference fields that points to the student and course content types.

Am I correct that these two ways are valid? And if I am correct, which one should I choose?

1 Answer 1


I know you won't like this answer but in general it depends:

What are your use cases when adding a new relationship? Is it more likely to add classes via students or the other way around? Or is it a migration process?

If UI is heavily used by both of the entites, I would give reference fields to both content types, and always update the other type reference field upon saving one type.

If this is more like for listing stuff (without editing on the UI these properties) and the information is coming from a big relationship list, then I would store it in a key-value table or a custom table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.