Skip to content

Commit 132741a

Browse files
committed
Trigger eager loading when using the attributes serializer option
1 parent fb75e16 commit 132741a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Bridge/Doctrine/Orm/Extension/EagerLoadingExtension.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGenerator
7979
$fetchPartial = $this->shouldOperationFetchPartial($resourceClass, $options);
8080
$serializerContext = $this->getSerializerContext($resourceClass, 'normalization_context', $options);
8181

82-
$groups = $this->getSerializerGroups($options, $serializerContext);
82+
$groups = $this->getPropertyMetadataOptions($options, $serializerContext);
8383

8484
$this->joinRelations($queryBuilder, $queryNameGenerator, $resourceClass, $forceEager, $fetchPartial, $queryBuilder->getRootAliases()[0], $groups, $serializerContext);
8585
}
@@ -99,9 +99,9 @@ public function applyToItem(QueryBuilder $queryBuilder, QueryNameGeneratorInterf
9999
$fetchPartial = $this->shouldOperationFetchPartial($resourceClass, $options);
100100
$contextType = isset($context['api_denormalize']) ? 'denormalization_context' : 'normalization_context';
101101
$serializerContext = $this->getSerializerContext($context['resource_class'] ?? $resourceClass, $contextType, $options);
102-
$groups = $this->getSerializerGroups($options, $serializerContext);
102+
$serializerOptions = $this->getPropertyMetadataOptions($options, $serializerContext);
103103

104-
$this->joinRelations($queryBuilder, $queryNameGenerator, $resourceClass, $forceEager, $fetchPartial, $queryBuilder->getRootAliases()[0], $groups, $serializerContext);
104+
$this->joinRelations($queryBuilder, $queryNameGenerator, $resourceClass, $forceEager, $fetchPartial, $queryBuilder->getRootAliases()[0], $serializerOptions, $serializerContext);
105105
}
106106

107107
/**
@@ -145,6 +145,7 @@ private function joinRelations(QueryBuilder $queryBuilder, QueryNameGeneratorInt
145145
continue;
146146
}
147147

148+
$attributes = $serializerContext[AbstractNormalizer::ATTRIBUTES] ?? null;
148149
if ((false === $propertyMetadata->isReadableLink() || false === $propertyMetadata->isReadable()) && false === $propertyMetadata->getAttribute('fetchEager', false)) {
149150
continue;
150151
}
@@ -261,12 +262,12 @@ private function getSerializerContext(string $resourceClass, string $contextType
261262
*
262263
* @param array $options represents the operation name so that groups are the one of the specific operation
263264
*/
264-
private function getSerializerGroups(array $options, array $context): array
265+
private function getPropertyMetadataOptions(array $options, array $context): array
265266
{
266-
if (empty($context[AbstractNormalizer::GROUPS])) {
267-
return $options;
267+
if (!empty($context[AbstractNormalizer::GROUPS])) {
268+
$options ['serializer_groups'] = $context[AbstractNormalizer::GROUPS];
268269
}
269270

270-
return ['serializer_groups' => $context[AbstractNormalizer::GROUPS]];
271+
return $options;
271272
}
272273
}

0 commit comments

Comments
 (0)