@@ -226,46 +226,49 @@ private function addSelect(QueryBuilder $queryBuilder, string $entity, string $a
226
226
$ select = [];
227
227
$ entityManager = $ queryBuilder ->getEntityManager ();
228
228
$ targetClassMetadata = $ entityManager ->getClassMetadata ($ entity );
229
- if ($ targetClassMetadata ->subClasses ) {
229
+ if (! empty ( $ targetClassMetadata ->subClasses ) ) {
230
230
$ queryBuilder ->addSelect ($ associationAlias );
231
- } else {
232
- foreach ($ this ->propertyNameCollectionFactory ->create ($ entity ) as $ property ) {
233
- $ propertyMetadata = $ this ->propertyMetadataFactory ->create ($ entity , $ property , $ propertyMetadataOptions );
234
231
235
- if (true === $ propertyMetadata ->isIdentifier ()) {
236
- $ select [] = $ property ;
237
- continue ;
238
- }
232
+ return ;
233
+ }
239
234
240
- //the field test allows to add methods to a Resource which do not reflect real database fields
241
- if ($ targetClassMetadata ->hasField ($ property ) && (true === $ propertyMetadata ->getAttribute ('fetchable ' ) || $ propertyMetadata ->isReadable ())) {
242
- $ select [] = $ property ;
243
- }
235
+ foreach ($ this ->propertyNameCollectionFactory ->create ($ entity ) as $ property ) {
236
+ $ propertyMetadata = $ this ->propertyMetadataFactory ->create ($ entity , $ property , $ propertyMetadataOptions );
244
237
245
- if (array_key_exists ($ property , $ targetClassMetadata ->embeddedClasses )) {
246
- foreach ($ this ->propertyNameCollectionFactory ->create ($ targetClassMetadata ->embeddedClasses [$ property ]['class ' ]) as $ embeddedProperty ) {
247
- $ propertyMetadata = $ this ->propertyMetadataFactory ->create ($ entity , $ property , $ propertyMetadataOptions );
248
- $ propertyName = "$ property. $ embeddedProperty " ;
249
- if ($ targetClassMetadata ->hasField ($ propertyName ) && (true === $ propertyMetadata ->getAttribute ('fetchable ' ) || $ propertyMetadata ->isReadable ())) {
250
- $ select [] = $ propertyName ;
251
- }
252
- }
253
- }
238
+ if (true === $ propertyMetadata ->isIdentifier ()) {
239
+ $ select [] = $ property ;
240
+ continue ;
254
241
}
255
242
256
- $ queryBuilder ->addSelect (sprintf ('partial %s.{%s} ' , $ associationAlias , implode (', ' , $ select )));
243
+ //the field test allows to add methods to a Resource which do not reflect real database fields
244
+ if ($ targetClassMetadata ->hasField ($ property ) && (true === $ propertyMetadata ->getAttribute ('fetchable ' ) || $ propertyMetadata ->isReadable ())) {
245
+ $ select [] = $ property ;
246
+ }
247
+
248
+ if (!array_key_exists ($ property , $ targetClassMetadata ->embeddedClasses )) {
249
+ continue ;
250
+ }
251
+
252
+ foreach ($ this ->propertyNameCollectionFactory ->create ($ targetClassMetadata ->embeddedClasses [$ property ]['class ' ]) as $ embeddedProperty ) {
253
+ $ propertyMetadata = $ this ->propertyMetadataFactory ->create ($ entity , $ property , $ propertyMetadataOptions );
254
+ $ propertyName = "$ property. $ embeddedProperty " ;
255
+ if ($ targetClassMetadata ->hasField ($ propertyName ) && (true === $ propertyMetadata ->getAttribute ('fetchable ' ) || $ propertyMetadata ->isReadable ())) {
256
+ $ select [] = $ propertyName ;
257
+ }
258
+ }
257
259
}
260
+
261
+ $ queryBuilder ->addSelect (sprintf ('partial %s.{%s} ' , $ associationAlias , implode (', ' , $ select )));
258
262
}
259
263
260
264
/**
261
- * Gets serializer context.
265
+ * Gets the serializer context.
262
266
*
263
267
* @param string $contextType normalization_context or denormalization_context
264
268
* @param array $options represents the operation name so that groups are the one of the specific operation
265
269
*/
266
270
private function getNormalizationContext (string $ resourceClass , string $ contextType , array $ options ): array
267
271
{
268
- $ request = null ;
269
272
if (null !== $ this ->requestStack && null !== $ this ->serializerContextBuilder && null !== $ request = $ this ->requestStack ->getCurrentRequest ()) {
270
273
return $ this ->serializerContextBuilder ->createFromRequest ($ request , 'normalization_context ' === $ contextType );
271
274
}
0 commit comments