Bonjour,

Je me retrouve confronté à un souci de conception que je ne sais pas traduire en yaml pour Doctrine.

Pour résumer mon cas :

J'ai des produits. Ces produits peuvent appartenir a des Kits de produits (plusieurs produits différents dans un kit).
Un même produit peut avoir une référence utilisateur par département.
Un même kit peut avoir une référence utilisateur par département.
Le stock dans le bunker et dans les labos est géré par référence utilisateur.

Voila (dans les grandes lignes) le schema que je génère (pardon c'est long):

Avant tout, le format Auditable est un format interne qui ajoute 2 colonnes : created_by et updated_by

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
Bunker:
  actAs:   { Auditable: ~ }
  columns:
    compartiment_id:  { type: integer, notnull: true }
    is_active:        { type: boolean, notnull: true, default: 1 }
  relations:
    Compartiment:     { onDelete: RESTRICT, local: compartiment_id, foreign: id, foreignAlias: Bunkers }
    StockBunkers:
      class: RefUtilisateur
      refClass: StockRefBunker
      local: bunker_id
      foreign: ref_user_id
      foreignAlias: Bunkers

Categorie:
  actAs: { Auditable: ~ }
  columns:
    name:      { type: string(255), notnull: true }
    is_active: { type: boolean, notnull: true, default: 1 }
    
Compartiment:
  actAs:   { Auditable: ~ }
  columns:
    name:      { type: string(50), notnull: true }
    is_active: { type: boolean, notnull: true, default: 1 }

Departement:
  actAs:  { Auditable: ~ }
  columns:
    name:      { type: string(30), notnull: true }
    is_active: { type: boolean, notnull: true, default: 1 }

Fabriquant:
  actAs: { Auditable: ~ }
  columns:
    name:      { type: string(255), notnull: true }
    is_ce:     { type: boolean, notnull: true }
    is_active: { type: boolean, notnull: true, default: 1 }

Fournisseur:
  actAs: { Auditable: ~ }
  columns:
    name:      { type: string(255), notnull: true }
    is_ce:     { type: boolean, notnull: true }
    is_active: { type: boolean, notnull: true, default: 1 }
      
Labo:
  actAs: { Auditable: ~ }
  columns:
    numero:         { type: string(50), notnull: true }
    departement_id: { type: integer, notnull: true }
    is_active:      { type: boolean, notnull: true, default: 1 }
  relations:
    Departement:    { onDelete: RESTRICT, local: departement_id, foreign: id, foreignAlias: Labos }
    StockLabos:
      class: RefUtilisateur
      refClass: StockRefLabo
      local: labo_id
      foreign: ref_user_id
      foreignAlias: Labos

Produit:
  actAs: { Auditable: ~ }
  columns:
    fournisseur_id:        { type: integer, notnull: true }
    fabriquant_id:         { type: integer, notnull: true }
    kit_id:                { type: integer }
    forme:                 { type: enum(7), values [ Liquide, Solide ], notnull: true }
    name:                  { type: string(50), notnull: true }
    categorie_id:          { type: integer, notnull: true }   
    n_inventaire:          { type: integer }
    ref_catalogue:         { type: string(50), notnull: true }
    ref_fabriquant:        { type: string(50) }
    formule_chimique:      { type: string(30) }
    n_cas:                 { type: integer }
    n_ce:                  { type: integer }
    fds_fournisseur:       { type: string(255) }
    fds_format_ce:         { type: boolean, notnull: true }
    fds_url:               { type: string(255) }
    vlep8h:                { type: integer }
    vlep15mn:              { type: integer }
    point_eclair:          { type: integer }
    point_autoinflammation:   { type: integer }   
    temperature_conservation: { type: enum(5), values: [ +20°, +4°, -20°, Autre ] }
    seuil_interne_maxi:       { type: integer }
    unite_seuil_interne_maxi: { type: enum(2), values: [ ml, g ] }
    qte_conditionnement:    { type: integer }
    unite_conditionnement:  { type: enum(2), values: [ ml, g ] }
    remarques:              { type: string() }
    is_active:              { type: boolean, notnull: true, default: 1 } 
  relations:
    Fournisseur: { onDelete: RESTRICT, local: fournisseur_id, foreign: id, foreignAlias: Produits }
    Fabriquant: { onDelete: RESTRICT, local: fabriquant_id, foreign: id, foreignAlias: Produits }
    Kit: { onDelete: RESTRICT, local: kit_id, foreign: id, foreignAlias: Produits }  
    Categorie: { onDelete: RESTRICT, local: categorie_id, foreign: id, foreignAlias: Produits }
  indexes:
    uniqueness:
      fields: [ name, fournisseur_id, ref_catalogue ]
      type: unique    

Kit:
  actAs: { Auditable: ~ }
  columns:
    fournisseur_id:  { type: integer, notnull: true }
    name:            { type: string(255), notnull: true }
    n_inventaire:    { type: integer }
    ref_catalogue:   { type: string(50) }
    is_active:       { type: boolean, notnull: true, default: 1 } 
  relations:           
    Fournisseur: { onDelete: RESTRICT, local: fournisseur_id, foreign: id, foreignAlias: Kits }

RefUtilisateur:
  actAs: { Auditable: ~ }
  columns:
    parent_id:     { type: integer, notnull: true }
    department_id: { type: integer, notnull: true }
    ref_user:      { type: string(50), notnull: true }
    type:          { type: enum(7), values: [ Produit, Kit ], notnull: true }
    is_active:     { type: boolean, notnull: true, default: 1 } 
  relations:
    Produit: { onDelete: RESTRICT, local: parent_id, foreign: id, foreignAlias: References Utilisateurs }
    Kit: { onDelete: RESTRICT, local: parent_id, foreign: id, foreignAlias: References Utilisateurs }
    Departement: { onDelete: RESTRICT, local: department_id, foreign: id, foreignAlias: References Utilisateurs }
  indexes:
    uniqueness:
      fields: [ parent_id, department_id, type ]
      type: unique 
    
StockRefLabo:
  actAs:  { Auditable: ~ }
  columns:
    ref_user_id:  { type: integer }
    labo_id:      { type: integer }
    quantite:     { type: integer }
  relations:
    Labo:           { onDelete: RESTRICT, local: labo_id, foreign: id, foreignAlias: Labos }
    RefUtilisateur: { onDelete: RESTRICT, local: ref_user_id, foreign: id, foreignAlias: RefsUtilisateurs }
    
StockRefBunker:
  actAs:  { Auditable: ~ }
  columns:
    ref_user_id:  { type: integer }
    bunker_id:    { type: integer }
    quantite:     { type: integer }
  relations:
    Bunker:         { onDelete: RESTRICT, local: bunker_id, foreign: id, foreignAlias: Bunkers }
    RefUtilisateur: { onDelete: RESTRICT, local: ref_user_id, foreign: id, foreignAlias: RefsUtilisateurs }
Je tique un peu sur la partie en rouge, car en fait c'est le couple [ parent_id, type ] qui désignera le produit ou le kit, mais je ne sais pas comment "forcer" un type en particulier si le parent_id est originaire d'une table ou d'une autre ...

Donc ma question est d'après vous est-ce possible de déclarer ceci en yml ?
Où pensez vous que je devrais carrément revoir mon schema ?