Search code examples
databasedatabase-designmany-to-manyuml

How many to many relationship on same table looks like in UML


I have a problem with understanding many to many relationships on the same table in UML.

A user in my database has permission which says who he is (an instructor or a student).

My problem is that I have an instructor who can have 0 or more students and a student who can have 0 or more instructors.

My idea is this:

My UML diagram

I am not sure If is it correct. Is there any better solution?

Thanks for your help all :)


Solution

  • It depends what do you want to achieve.

    If you're trying to build a documentation of your database using UML then your model will not differ from what you would do using e.g. crowfoot notation. In such case, your diagram is correct.

    To emphasise the relationship you may use an association class linking User with User. It's bringing value only if your association class brings any additional value (attributes), otherwise, you can use a simple association.

    If you're focusing on showing the actual dependencies rather than what you have in your database, you may consider having User as a parent to two classes Teacher and Student and then depict your association as on between Teacher and Student rather than between Users.