diff --git a/src/Persisters/Entity/BasicEntityPersister.php b/src/Persisters/Entity/BasicEntityPersister.php index 1bb54ed4410..1a6444e7388 100644 --- a/src/Persisters/Entity/BasicEntityPersister.php +++ b/src/Persisters/Entity/BasicEntityPersister.php @@ -1332,6 +1332,12 @@ protected function getSelectColumnsSQL(): string $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 6183b9c56e2..9012895e595 100644 --- a/tests/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Tests/ORM/Functional/SQLFilterTest.php @@ -503,6 +503,21 @@ public function testToOneFilter(): void self::assertEquals(2, count($query->getResult())); } + public function testOneToOneInverseSideWithFilter(): void + { + $this->loadFixtureData(); + + $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); + } + public function testManyToManyFilter(): void { $this->loadFixtureData();