@@ -140,64 +140,78 @@ public function generateFieldAnnotations(string $className, string $fieldName):
140
140
}
141
141
142
142
$ annotations [] = $ annotation ;
143
- } elseif ($ field ['isEmbedded ' ]) {
143
+
144
+ return $ annotations ;
145
+ }
146
+
147
+ $ relationName = $ field ['range ' ] ? $ this ->getRelationName ($ field ['range ' ]) : null ;
148
+ if ($ field ['isEmbedded ' ]) {
144
149
$ columnPrefix = ', columnPrefix= ' ;
145
150
if (\is_bool ($ field ['columnPrefix ' ])) {
146
151
$ columnPrefix .= $ field ['columnPrefix ' ] ? 'true ' : 'false ' ;
147
152
} else {
148
153
$ columnPrefix .= sprintf ('"%s" ' , $ field ['columnPrefix ' ]);
149
154
}
150
- $ annotations [] = sprintf ('@ORM\Embedded(class="%s"%s) ' , $ this ->getRelationName ($ field ['range ' ]), $ columnPrefix );
151
- } else {
152
- switch ($ field ['cardinality ' ]) {
153
- case CardinalitiesExtractor::CARDINALITY_0_1 :
154
- $ annotations [] = sprintf ('@ORM\OneToOne(targetEntity="%s") ' , $ this ->getRelationName ($ field ['range ' ]));
155
- break ;
156
- case CardinalitiesExtractor::CARDINALITY_1_1 :
157
- $ annotations [] = sprintf ('@ORM\OneToOne(targetEntity="%s") ' , $ this ->getRelationName ($ field ['range ' ]));
158
- $ annotations [] = '@ORM\JoinColumn(nullable=false) ' ;
159
- break ;
160
- case CardinalitiesExtractor::CARDINALITY_UNKNOWN :
161
- case CardinalitiesExtractor::CARDINALITY_N_0 :
162
- if ($ field ['inversedBy ' ] ?? false ) {
163
- $ annotations [] = sprintf ('@ORM\ManyToOne(targetEntity="%s", inversedBy="%s") ' , $ this ->getRelationName ($ field ['range ' ]), $ field ['inversedBy ' ]);
164
- } else {
165
- $ annotations [] = sprintf ('@ORM\ManyToOne(targetEntity="%s") ' , $ this ->getRelationName ($ field ['range ' ]));
166
- }
167
- break ;
168
- case CardinalitiesExtractor::CARDINALITY_N_1 :
169
- if ($ field ['inversedBy ' ] ?? false ) {
170
- $ annotations [] = sprintf ('@ORM\ManyToOne(targetEntity="%s", inversedBy="%s") ' , $ this ->getRelationName ($ field ['range ' ]), $ field ['inversedBy ' ]);
171
- } else {
172
- $ annotations [] = sprintf ('@ORM\ManyToOne(targetEntity="%s") ' , $ this ->getRelationName ($ field ['range ' ]));
173
- }
174
- $ annotations [] = '@ORM\JoinColumn(nullable=false) ' ;
175
- break ;
176
- case CardinalitiesExtractor::CARDINALITY_0_N :
177
- if ($ field ['mappedBy ' ] ?? false ) {
178
- $ annotations [] = sprintf ('@ORM\OneToMany(targetEntity="%s", mappedBy="%s") ' , $ this ->getRelationName ($ field ['range ' ]), $ field ['mappedBy ' ]);
179
- } else {
180
- $ annotations [] = sprintf ('@ORM\ManyToMany(targetEntity="%s") ' , $ this ->getRelationName ($ field ['range ' ]));
181
- }
182
- $ name = $ field ['relationTableName ' ] ? sprintf ('name="%s", ' , $ field ['relationTableName ' ]) : '' ;
183
- $ annotations [] = '@ORM\JoinTable( ' .$ name .'inverseJoinColumns={@ORM\JoinColumn(unique=true)}) ' ;
184
- break ;
185
- case CardinalitiesExtractor::CARDINALITY_1_N :
186
- if ($ field ['mappedBy ' ] ?? false ) {
187
- $ annotations [] = sprintf ('@ORM\OneToMany(targetEntity="%s", mappedBy="%s") ' , $ this ->getRelationName ($ field ['range ' ]), $ field ['mappedBy ' ]);
188
- } else {
189
- $ annotations [] = sprintf ('@ORM\ManyToMany(targetEntity="%s") ' , $ this ->getRelationName ($ field ['range ' ]));
190
- }
191
- $ name = $ field ['relationTableName ' ] ? sprintf ('name="%s", ' , $ field ['relationTableName ' ]) : '' ;
192
- $ annotations [] = '@ORM\JoinTable( ' .$ name .'inverseJoinColumns={@ORM\JoinColumn(nullable=false, unique=true)}) ' ;
193
- break ;
194
- case CardinalitiesExtractor::CARDINALITY_N_N :
195
- $ annotations [] = sprintf ('@ORM\ManyToMany(targetEntity="%s") ' , $ this ->getRelationName ($ field ['range ' ]));
196
- if ($ field ['relationTableName ' ]) {
197
- $ annotations [] = sprintf ('@ORM\JoinTable(name="%s") ' , $ field ['relationTableName ' ]);
198
- }
199
- break ;
155
+
156
+ if ($ relationName ) {
157
+ $ annotations [] = sprintf ('@ORM\Embedded(class="%s"%s) ' , $ relationName , $ columnPrefix );
200
158
}
159
+
160
+ return $ annotations ;
161
+ }
162
+
163
+ if (!$ relationName ) {
164
+ return $ annotations ;
165
+ }
166
+
167
+ switch ($ field ['cardinality ' ]) {
168
+ case CardinalitiesExtractor::CARDINALITY_0_1 :
169
+ $ annotations [] = sprintf ('@ORM\OneToOne(targetEntity="%s") ' , $ relationName );
170
+ break ;
171
+ case CardinalitiesExtractor::CARDINALITY_1_1 :
172
+ $ annotations [] = sprintf ('@ORM\OneToOne(targetEntity="%s") ' , $ relationName );
173
+ $ annotations [] = '@ORM\JoinColumn(nullable=false) ' ;
174
+ break ;
175
+ case CardinalitiesExtractor::CARDINALITY_UNKNOWN :
176
+ case CardinalitiesExtractor::CARDINALITY_N_0 :
177
+ if ($ field ['inversedBy ' ] ?? false ) {
178
+ $ annotations [] = sprintf ('@ORM\ManyToOne(targetEntity="%s", inversedBy="%s") ' , $ relationName , $ field ['inversedBy ' ]);
179
+ } else {
180
+ $ annotations [] = sprintf ('@ORM\ManyToOne(targetEntity="%s") ' , $ relationName );
181
+ }
182
+ break ;
183
+ case CardinalitiesExtractor::CARDINALITY_N_1 :
184
+ if ($ field ['inversedBy ' ] ?? false ) {
185
+ $ annotations [] = sprintf ('@ORM\ManyToOne(targetEntity="%s", inversedBy="%s") ' , $ relationName , $ field ['inversedBy ' ]);
186
+ } else {
187
+ $ annotations [] = sprintf ('@ORM\ManyToOne(targetEntity="%s") ' , $ relationName );
188
+ }
189
+ $ annotations [] = '@ORM\JoinColumn(nullable=false) ' ;
190
+ break ;
191
+ case CardinalitiesExtractor::CARDINALITY_0_N :
192
+ if ($ field ['mappedBy ' ] ?? false ) {
193
+ $ annotations [] = sprintf ('@ORM\OneToMany(targetEntity="%s", mappedBy="%s") ' , $ relationName , $ field ['mappedBy ' ]);
194
+ } else {
195
+ $ annotations [] = sprintf ('@ORM\ManyToMany(targetEntity="%s") ' , $ relationName );
196
+ }
197
+ $ name = $ field ['relationTableName ' ] ? sprintf ('name="%s", ' , $ field ['relationTableName ' ]) : '' ;
198
+ $ annotations [] = '@ORM\JoinTable( ' .$ name .'inverseJoinColumns={@ORM\JoinColumn(unique=true)}) ' ;
199
+ break ;
200
+ case CardinalitiesExtractor::CARDINALITY_1_N :
201
+ if ($ field ['mappedBy ' ] ?? false ) {
202
+ $ annotations [] = sprintf ('@ORM\OneToMany(targetEntity="%s", mappedBy="%s") ' , $ relationName , $ field ['mappedBy ' ]);
203
+ } else {
204
+ $ annotations [] = sprintf ('@ORM\ManyToMany(targetEntity="%s") ' , $ relationName );
205
+ }
206
+ $ name = $ field ['relationTableName ' ] ? sprintf ('name="%s", ' , $ field ['relationTableName ' ]) : '' ;
207
+ $ annotations [] = '@ORM\JoinTable( ' .$ name .'inverseJoinColumns={@ORM\JoinColumn(nullable=false, unique=true)}) ' ;
208
+ break ;
209
+ case CardinalitiesExtractor::CARDINALITY_N_N :
210
+ $ annotations [] = sprintf ('@ORM\ManyToMany(targetEntity="%s") ' , $ relationName );
211
+ if ($ field ['relationTableName ' ]) {
212
+ $ annotations [] = sprintf ('@ORM\JoinTable(name="%s") ' , $ field ['relationTableName ' ]);
213
+ }
214
+ break ;
201
215
}
202
216
203
217
return $ annotations ;
@@ -243,8 +257,12 @@ private function generateIdAnnotations(): array
243
257
/**
244
258
* Gets class or interface name to use in relations.
245
259
*/
246
- private function getRelationName (string $ range ): string
260
+ private function getRelationName (string $ range ): ? string
247
261
{
262
+ if (!isset ($ this ->classes [$ range ])) {
263
+ return null ;
264
+ }
265
+
248
266
$ class = $ this ->classes [$ range ];
249
267
250
268
if (isset ($ class ['interfaceName ' ])) {
0 commit comments