Skip to content

Commit cf85322

Browse files
committed
Make EagerLoadingExtension robuster and less complex
1 parent 0ecd217 commit cf85322

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function applyToItem(QueryBuilder $queryBuilder, QueryNameGeneratorInterf
111111
}
112112

113113
/**
114-
* Left joins relations to eager load.
114+
* Joins relations to eager load.
115115
*
116116
* @param QueryBuilder $queryBuilder
117117
* @param string $resourceClass
@@ -131,8 +131,7 @@ private function joinRelations(QueryBuilder $queryBuilder, string $resourceClass
131131

132132
$entityManager = $queryBuilder->getEntityManager();
133133
$classMetadata = $entityManager->getClassMetadata($resourceClass);
134-
$j = 0;
135-
$i = 0;
134+
$i = $j = 0;
136135

137136
foreach ($classMetadata->associationMappings as $association => $mapping) {
138137
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $association, $propertyMetadataOptions);
@@ -145,16 +144,11 @@ private function joinRelations(QueryBuilder $queryBuilder, string $resourceClass
145144
continue;
146145
}
147146

148-
if (false === $wasLeftJoin) {
149-
$joinColumns = $mapping['joinColumns'] ?? $mapping['joinTable']['joinColumns'] ?? null;
150-
151-
if (null === $joinColumns) {
152-
$method = 'leftJoin';
153-
} else {
154-
$method = false === $joinColumns[0]['nullable'] ? 'innerJoin' : 'leftJoin';
155-
}
156-
} else {
147+
$joinColumns = $mapping['joinColumns'] ?? $mapping['joinTable']['joinColumns'] ?? null;
148+
if (false !== $wasLeftJoin || !isset($joinColumns[0]['nullable']) || false !== $joinColumns[0]['nullable']) {
157149
$method = 'leftJoin';
150+
} else {
151+
$method = 'innerJoin';
158152
}
159153

160154
$associationAlias = $relationAlias.$i++;

0 commit comments

Comments
 (0)