diff --git a/src/Persisters/Entity/BasicEntityPersister.php b/src/Persisters/Entity/BasicEntityPersister.php index 9bd8afd3cc1..75ab581e2b0 100644 --- a/src/Persisters/Entity/BasicEntityPersister.php +++ b/src/Persisters/Entity/BasicEntityPersister.php @@ -1374,6 +1374,12 @@ protected function getSelectColumnsSQL() $joinCondition[] = $this->getSQLTableAlias($association['sourceEntity'], $assocAlias) . '.' . $sourceCol . ' = ' . $this->getSQLTableAlias($association['targetEntity']) . '.' . $targetCol; } + + // Add filter SQL + $filterSql = $this->generateFilterConditionSQL($eagerEntity, $joinTableAlias); + if ($filterSql) { + $joinCondition[] = $filterSql; + } } $this->currentPersisterContext->selectJoinSql .= ' ' . $joinTableName . ' ' . $joinTableAlias . ' ON '; diff --git a/tests/Tests/ORM/Functional/SQLFilterTest.php b/tests/Tests/ORM/Functional/SQLFilterTest.php index a4c8823c834..8e701cd36cd 100644 --- a/tests/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Tests/ORM/Functional/SQLFilterTest.php @@ -593,6 +593,21 @@ private function loadLazyFixtureData(): void $this->loadFixtureData(); } + public function testOneToOneExtraLazyWithFilter(): void + { + $this->loadLazyFixtureData(); + + $conf = $this->_em->getConfiguration(); + $conf->addFilter('country', '\Doctrine\Tests\ORM\Functional\CMSCountryFilter'); + $this->_em->getFilters()->enable('country')->setParameterList('country', ['Germany'], Types::STRING); + + $user = $this->_em->find(CmsUser::class, $this->userId); + self::assertNotEmpty($user->address); + + $user2 = $this->_em->find(CmsUser::class, $this->userId2); + self::assertEmpty($user2->address); + } + private function useCMSArticleTopicFilter(): void { $conf = $this->_em->getConfiguration();