Skip to content

Commit a67f677

Browse files
authored
Merge pull request #11707 from jorenMartens/2.20.x
[DDC-551] fix, add filter support in oneToOne relation 2.20.x
2 parents 19912de + 1486646 commit a67f677

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Persisters/Entity/BasicEntityPersister.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,12 @@ protected function getSelectColumnsSQL()
13741374
$joinCondition[] = $this->getSQLTableAlias($association['sourceEntity'], $assocAlias) . '.' . $sourceCol . ' = '
13751375
. $this->getSQLTableAlias($association['targetEntity']) . '.' . $targetCol;
13761376
}
1377+
1378+
// Add filter SQL
1379+
$filterSql = $this->generateFilterConditionSQL($eagerEntity, $joinTableAlias);
1380+
if ($filterSql) {
1381+
$joinCondition[] = $filterSql;
1382+
}
13771383
}
13781384

13791385
$this->currentPersisterContext->selectJoinSql .= ' ' . $joinTableName . ' ' . $joinTableAlias . ' ON ';

tests/Tests/ORM/Functional/SQLFilterTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,21 @@ public function testToOneFilter(): void
537537
self::assertEquals(2, count($query->getResult()));
538538
}
539539

540+
public function testOneToOneInverseSideWithFilter(): void
541+
{
542+
$this->loadFixtureData();
543+
544+
$conf = $this->_em->getConfiguration();
545+
$conf->addFilter('country', '\Doctrine\Tests\ORM\Functional\CMSCountryFilter');
546+
$this->_em->getFilters()->enable('country')->setParameterList('country', ['Germany'], Types::STRING);
547+
548+
$user = $this->_em->find(CmsUser::class, $this->userId);
549+
self::assertNotEmpty($user->address);
550+
551+
$user2 = $this->_em->find(CmsUser::class, $this->userId2);
552+
self::assertEmpty($user2->address);
553+
}
554+
540555
public function testManyToManyFilter(): void
541556
{
542557
$this->loadFixtureData();

0 commit comments

Comments
 (0)