Bonjour,
J'ai cherché partout, mais je n'ai pas trouvé la solution à mon problème.
J'ai deux tables (tr_composant et tr_noeud) liées par une relation many-to-many, j'ai donc crée une table "entre les deux" (tr_composant_noeud).
Voici le schéma :
Et voici mon formulaire :
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212 TrNoeud: connection: doctrine tableName: tr_noeud columns: nd_id: type: integer(4) fixed: false unsigned: false primary: true autoincrement: true nd_code: type: string(255) fixed: false unsigned: false primary: false notnull: true autoincrement: false nd_nom: type: string(255) fixed: false unsigned: false primary: false notnull: true autoincrement: false nd_description: type: string(255) fixed: false unsigned: false primary: false notnull: false autoincrement: false nd_lft: type: integer(4) fixed: false unsigned: false primary: false notnull: false autoincrement: false nd_rgt: type: integer(4) fixed: false unsigned: false primary: false notnull: false autoincrement: false nd_nlevel: type: integer(4) fixed: false unsigned: false primary: false notnull: false autoincrement: false nd_code_createur: type: string(255) fixed: false unsigned: false primary: false notnull: true autoincrement: false nd_code_modifieur: type: string(255) fixed: false unsigned: false primary: false notnull: false autoincrement: false created_at: type: timestamp(25) fixed: false unsigned: false primary: false notnull: true autoincrement: false updated_at: type: timestamp(25) fixed: false unsigned: false primary: false notnull: true autoincrement: false nd_ndt_id: type: integer(4) fixed: false unsigned: false primary: false notnull: true autoincrement: false relations: TrComposantNoeud: local: nd_id foreign: com_nd_nd_id type: many TrComposant: connection: doctrine tableName: tr_composant columns: com_id: type: integer(4) fixed: false unsigned: false primary: true autoincrement: true com_code: type: string(255) fixed: false unsigned: false primary: false notnull: true autoincrement: false com_nom: type: string(255) fixed: false unsigned: false primary: false notnull: true autoincrement: false com_description: type: string(255) fixed: false unsigned: false primary: false notnull: false autoincrement: false com_code_createur: type: string(255) fixed: false unsigned: false primary: false notnull: true autoincrement: false com_code_modifieur: type: string(255) fixed: false unsigned: false primary: false notnull: false autoincrement: false created_at: type: timestamp(25) fixed: false unsigned: false primary: false notnull: true autoincrement: false updated_at: type: timestamp(25) fixed: false unsigned: false primary: false notnull: true autoincrement: false relations: TrComposantNoeud: local: com_id foreign: com_nd_com_id type: many TrComposantNoeud: connection: doctrine tableName: tr_composant_noeud columns: com_nd_com_id: type: integer(4) fixed: false unsigned: false primary: true autoincrement: false com_nd_nd_id: type: integer(4) fixed: false unsigned: false primary: true autoincrement: false com_nd_code_createur: type: string(255) fixed: false unsigned: false primary: false notnull: true autoincrement: false com_nd_code_modifieur: type: string(255) fixed: false unsigned: false primary: false notnull: false autoincrement: false created_at: type: timestamp(25) fixed: false unsigned: false primary: false notnull: true autoincrement: false updated_at: type: timestamp(25) fixed: false unsigned: false primary: false notnull: true autoincrement: false relations: TrNoeud: local: com_nd_nd_id foreign: nd_id type: one TrComposant: local: com_nd_com_id foreign: com_id type: one
Et la base du formulaire :
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 class TrComposantNoeudForm extends BaseTrComposantNoeudForm { public function setup() { parent::setup(); unset( $this['com_nd_com_id'], $this['com_nd_nd_id'], ); $this->widgetSchema['com_nd_nd_id']= new sfWidgetFormDoctrineChoice(array('model' => 'TrNoeud', 'add_empty' => false) ); $this->widgetSchema['com_nd_com_id']= new sfWidgetFormDoctrineChoice(array('model' => 'TrComposant', 'add_empty' => false) ); $this->setValidators(array( 'com_nd_nd_id' => new sfValidatorDoctrineChoice(array('model' => $this->getModelName(), 'column' => 'com_nd_nd_id')), 'com_nd_com_id' => new sfValidatorDoctrineChoice(array('model' => $this->getModelName(), 'column' => 'com_nd_com_id')), )); $this->widgetSchema->setLabels(array( 'com_nd_com_id' => 'Nom du composant', 'com_nd_nd_id' => 'Noeud', )); } }
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 abstract class BaseTrComposantNoeudForm extends BaseFormDoctrine { public function setup() { $this->setWidgets(array( 'com_nd_com_id' => new sfWidgetFormInputHidden(), 'com_nd_nd_id' => new sfWidgetFormInputHidden(), 'com_nd_code_createur' => new sfWidgetFormInputText(), 'com_nd_code_modifieur' => new sfWidgetFormInputText(), 'created_at' => new sfWidgetFormDateTime(), 'updated_at' => new sfWidgetFormDateTime(), )); $this->setValidators(array( 'com_nd_com_id' => new sfValidatorDoctrineChoice(array('model' => $this->getModelName(), 'column' => 'com_nd_com_id', 'required' => false)), 'com_nd_nd_id' => new sfValidatorDoctrineChoice(array('model' => $this->getModelName(), 'column' => 'com_nd_nd_id', 'required' => false)), 'com_nd_code_createur' => new sfValidatorString(array('max_length' => 255)), 'com_nd_code_modifieur' => new sfValidatorString(array('max_length' => 255, 'required' => false)), 'created_at' => new sfValidatorDateTime(), 'updated_at' => new sfValidatorDateTime(), )); $this->widgetSchema->setNameFormat('tr_composant_noeud[%s]'); $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema); $this->setupInheritance(); parent::setup(); } public function getModelName() { return 'TrComposantNoeud'; } }
Mon problème est : lorsque je crée une nouvelle entité de tr_composant_noeud, un message d'erreur apparaît :
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'com_nd_nd_id' cannot be null
C'est comme si le formulaire n'arrivait pas à trouver le noeud que j'ai sélectionné dans la liste.
Si vous avez des idées, je prend !
En vous remerciant de prendre le temps de regarder mon problème,
Bonne journée!
Partager