Harley
Harley

Reputation: 1534

ER Diagrams - Can someone please explain modality?

ER Diagrams - Can someone please explain modality?

Modality - one at both ends

Above: If there is a module it must belong to a course. And if there is a course we'd really like there to be a module. But is the diagram correct?

The foreign key constraint enforces that if a module exists in the child table then there will be a course in the parent table. But there is no constraint the other way, and obviously you have to create one record before the other.

So, is this more correct (below)?

Modality - one at one end, zero at the other

Or does modality zero mean the FK can be null?

Upvotes: 0

Views: 1423

Answers (1)

pdem
pdem

Reputation: 4076

  1. The first diagram is correct
  2. No the "O" on the right only mean you allow to have a course with no modules, it's a 0-n relation.

So the first one mean 1-n relation , what you want, but you can't enforce 1-n more than 0-n in SQL. Using "|<" is for documentation, and code implementation, and not for SQL constraint.

The meaning of your convention:
ERD legend

Side note: I prefer the UML "0-n" notation which is more explicit, here would be the result in plantUML: (use planttext.com for the render)
enter image description here

@startuml
title Relationships - Class Diagram
class Courses
class Modules
Courses "1" *-up- "1-n" Modules: Composition
@enduml

Upvotes: 1

Related Questions