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