Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/Doctrine/Orm/Extension/EagerLoadingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ private function joinRelations(QueryBuilder $queryBuilder, QueryNameGeneratorInt
}

$currentDepth = $currentDepth > 0 ? $currentDepth - 1 : $currentDepth;
$entityManager = $queryBuilder->getEntityManager();
$classMetadata = $entityManager->getClassMetadata($resourceClass);
$classMetadata = $queryBuilder->getEntityManager()->getClassMetadata($resourceClass);
$attributesMetadata = $this->classMetadataFactory?->getMetadataFor($resourceClass)->getAttributesMetadata();

foreach ($classMetadata->associationMappings as $association => $mapping) {
Expand All @@ -123,6 +122,23 @@ private function joinRelations(QueryBuilder $queryBuilder, QueryNameGeneratorInt
continue;
}

// prepare the child context
$childNormalizationContext = $normalizationContext;
if (isset($normalizationContext[AbstractNormalizer::ATTRIBUTES])) {
if ($inAttributes = isset($normalizationContext[AbstractNormalizer::ATTRIBUTES][$association])) {
$childNormalizationContext[AbstractNormalizer::ATTRIBUTES] = $normalizationContext[AbstractNormalizer::ATTRIBUTES][$association];
}
} else {
$inAttributes = null;
}

if (true !== $inAttributes
&& isset($attributesMetadata[$association])
&& empty(array_intersect($normalizationContext[AbstractNormalizer::GROUPS] ?? [], $attributesMetadata[$association]->getGroups()))) {
// Skip this association if the current normalization groups do not include the association's groups
continue;
}

try {
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $association, $options);
} catch (PropertyNotFoundException) {
Expand All @@ -143,16 +159,6 @@ private function joinRelations(QueryBuilder $queryBuilder, QueryNameGeneratorInt
continue;
}

// prepare the child context
$childNormalizationContext = $normalizationContext;
if (isset($normalizationContext[AbstractNormalizer::ATTRIBUTES])) {
if ($inAttributes = isset($normalizationContext[AbstractNormalizer::ATTRIBUTES][$association])) {
$childNormalizationContext[AbstractNormalizer::ATTRIBUTES] = $normalizationContext[AbstractNormalizer::ATTRIBUTES][$association];
}
} else {
$inAttributes = null;
}

$fetchEager = $propertyMetadata->getFetchEager();
$uriTemplate = $propertyMetadata->getUriTemplate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,11 @@

$dummyAttributeMetadata = new AttributeMetadata('dummy');
$dummyAttributeMetadata->setMaxDepth(2);
$dummyAttributeMetadata->addGroup('foo');

Check warning on line 430 in src/Doctrine/Orm/Tests/Extension/EagerLoadingExtensionTest.php

View check run for this annotation

Codecov / codecov/patch

src/Doctrine/Orm/Tests/Extension/EagerLoadingExtensionTest.php#L430

Added line #L430 was not covered by tests

$relatedAttributeMetadata = new AttributeMetadata('relatedDummy');
$relatedAttributeMetadata->setMaxDepth(4);
$relatedAttributeMetadata->addGroup('foo');

Check warning on line 434 in src/Doctrine/Orm/Tests/Extension/EagerLoadingExtensionTest.php

View check run for this annotation

Codecov / codecov/patch

src/Doctrine/Orm/Tests/Extension/EagerLoadingExtensionTest.php#L434

Added line #L434 was not covered by tests

$dummyClassMetadataInterfaceProphecy->getAttributesMetadata()->willReturn(['relatedDummy' => $dummyAttributeMetadata]);
$relatedClassMetadataInterfaceProphecy->getAttributesMetadata()->willReturn(['dummy' => $relatedAttributeMetadata]);
Expand Down
Loading