Skip to content

3.2 ER Diagrams

Julio Toboso edited this page Apr 27, 2026 · 1 revision

Great question. You can cover E/R + EER nicely in GitHub Wiki using only what GitHub renders natively:

  • Mermaid for diagrams.
  • MathJax for min–max/cardinality annotations.
  • (Optionally) Mermaid flowchart/class diagrams to emulate EER features Mermaid-ER doesn’t natively show.

Below is a compact toolbox you can paste into your wiki and adapt.


1) Core Entity–Relationship (Mermaid ER)

Use Mermaid’s erDiagram for entities, attributes, and crow’s-foot cardinalities.

erDiagram
  PERSON {
    string DNI PK
    string nombre
    string direccion
  }

  HOUSE {
    string id PK
    string calle
    int numero
  }

  MUNICIPALITY {
    string id PK
    string nombre
  }

  %% 1:N
  PERSON ||--o{ HOUSE : HABITA
  %% N:M
  PERSON }o--o{ HOUSE : PROPIEDAD
  %% N:1
  HOUSE  }o--|| MUNICIPALITY : UBICADA_EN

Loading

Tips:

  • || = “1”, o = “0”, { = “many”.
  • Put the Spanish verb as the edge label (e.g., "HABITA").

2) Min–max constraints (MathJax label)

When you need $((\text{min},\text{max}))$ exactly (e.g., ((0,1)), ((1,N))), add a small legend line right below the ER block:

**Cardinalidades (min–max)**:  
- HABITA: $PERSONA\ (1,N)$ — $VIVIENDA\ (0,N)$  
- UBICADA\_EN: $VIVIENDA\ (1,1)$ — $MUNICIPIO\ (1,N)$

Cardinalidades (min–max):

  • HABITA: $PERSONA\ (1,N)$ — $VIVIENDA\ (0,N)$
  • UBICADA_EN: $VIVIENDA\ (1,1)$ — $MUNICIPIO\ (1,N)$

(You can also put (0,1) or (1,N) as part of the edge label text in the ER diagram if you prefer.)


3) Débil/Identificadora (approx.)

Mermaid-ER doesn’t have “doble borde”/weak notation. Two practical approximations:

A) Tag + legend (simplísimo)

  • Nombra la entidad como PAGO [débil].
  • Añade una nota abajo: “Entidad débil: identificada por VÍNCULO con ALUMNO + clave parcial.”

B) Flowchart con estilo (si quieres visual distinto)

flowchart LR
  classDef weak stroke-width:3px,stroke-dasharray: 6 3,rx:6,ry:6
  classDef ident stroke-width:3px,stroke:gray

  ALUMNO([ALUMNO]):::ident -->|VÍNCULO IDENTIFICADOR| PAGO([PAGO]):::weak
  note1[Clave parcial: Nº_Pago]:::weak
  PAGO --- note1
Loading

Use este flowchart solo para ilustrar “débil + identificadora” cuando haga falta; mantén el ER principal en erDiagram.


4) Especialización/Generalización (ISA)

Mermaid classDiagram funciona muy bien para jerarquías:

classDiagram
  class EMPLEADO{
    DNI
    nombre
    fecha_contratacion
  }
  class AGENTE
  class ADMINISTRATIVO

  EMPLEADO <|-- AGENTE
  EMPLEADO <|-- ADMINISTRATIVO

  %% Opcional: anota disjunta/solapada, total/parcial en una nota:
  note for EMPLEADO "Especialización disjunta, parcial"
Loading

Añade al lado una línea con MathJax si quieres ser formal:

Disjunción: $AGENTE \cap ADMINISTRATIVO = \varnothing$; Totalidad: no (parcial).

5) Relaciones ternarias o con atributos de relación

Mermaid-ER no modela “atributos de relación” directamente. Dos trucos:

  • Interponer entidad-join (estándar de paso a relacional):
erDiagram
  CLIENTE ||--o{ RESERVA : ""
  VIAJE   ||--o{ RESERVA : ""
  RESERVA {
    string id PK
    date fecha_reserva
    int plazas
  }
Loading
  • Ternaria → representa con entidad intermedia nombrada con el verbo compuesto, y documenta en texto que es ternaria.

6) Participación total/parcial

No hay “borde doble” automático. Anótalo en el label o en una lista bajo el diagrama:

**Participación**  
- DIRIGE: *Total* en DEPARTAMENTO respecto a GERENTE.  
- TRABAJA_PARA: *Total* en ambos sentidos.  

(Usa negritas/itálicas, o símbolos ✅/⚪ para total/parcial.)


7) Piezas listas para copiar (plantillas)

ER “Municipio–Vivienda–Persona”

erDiagram
  PERSONA {
    string id PK
    string nombre
  }
  VIVIENDA {
    string id PK
    string direccion
  }
  MUNICIPIO {
    string id PK
    string nombre
  }

  PERSONA ||--o{ VIVIENDA : "HABITA"
  PERSONA }o--o{ VIVIENDA : "PROPIEDAD"
  VIVIENDA }o--|| MUNICIPIO : "UBICADA_EN"
Loading

Jerarquía empleado

classDiagram
  class EMPLEADO{
    DNI
    nombre
    fecha_contratacion
  }
  class RECEPCIONISTA{
    idioma_principal
  }
  class CAMARERO{
    area_asignada
  }
  EMPLEADO <|-- RECEPCIONISTA
  EMPLEADO <|-- CAMARERO
Loading

Data

Legend:

  • 🔰 Start here
  • 🏵️ Important Insight
  • ⚙️ Technical and applications
  • 💻 Some Code
  • ⚜️ Advanced Topics

Start

01 · Ω — What could happen

02 · X, 𝒳 — What we observe

03 · p(x) — What we expected

04 · I(x), H(X) — What an observation tells us

05 · Data — What is consistent

06 · Statistics — What we can learn.

07 · Databases - How to store data

08 · μ(x) — Fuzzy - When data is flexible

  • 08.1 Fuzzy Logic (planned)
  • 08.2 Fuzzy Numbers (planned)
  • 08.3 Possibility vs Probability (planned)

09 · x(t) — Signals and systems - Where patterns live

  • 09.1 Signals (stub)
  • 09.2 Sampling and Aliasing (planned)
  • 09.3 Convolution (planned)
  • 09.4 Frequency (planned)

10 · f_θ — Modelling and linear algebra

  • 10.1 🔰 Vectors and Matrices (planned)
  • 10.2 Mathematical Modelling (planned)

11 · min L(θ) — Optimisation

  • 11.1 🔰 Derivatives (planned)
  • 11.2 Convex Optimisation (planned)

12 · Learning from data

13 · Cause, design, capstone

  • 13.1 Cause and Effect (planned)
  • 13.2 Capstone Guide (planned)

Appendix

Clone this wiki locally