3.2 ER Diagrams - JulTob/Data GitHub Wiki
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
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
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"
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
}
- 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"
Jerarquía empleado
classDiagram
class EMPLEADO{
DNI
nombre
fecha_contratacion
}
class RECEPCIONISTA{
idioma_principal
}
class CAMARERO{
area_asignada
}
EMPLEADO <|-- RECEPCIONISTA
EMPLEADO <|-- CAMARERO