Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate WITH in joined associations #10979

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 8 additions & 0 deletions lib/Doctrine/ORM/Query/SqlWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,14 @@ public function walkJoinAssociationDeclaration($joinAssociationDeclaration, $joi
}

if ($withCondition) {
if (isset($this->selectedClasses[$joinedDqlAlias])) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/10978',
'WITH join conditions are deprecated for joins on associations. Use either a sub-select with another occurance of this table or use Collection::matching(Criteria) in follow-up code.'
);
}

$sql .= ' AND ' . $withCondition;
}

Expand Down
5 changes: 0 additions & 5 deletions tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,6 @@ public function testAllExpressionWithCorrelatedSubquery(): void
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > ALL (SELECT u2.id FROM Doctrine\Tests\Models\CMS\CmsUser u2 WHERE u2.name = u.name)');
}

public function testCustomJoinsAndWithKeywordSupported(): void
{
$this->assertValidDQL('SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.phonenumbers p WITH p.phonenumber = 123 WHERE u.id = 1');
}

public function testAnyExpressionWithCorrelatedSubquery(): void
{
$this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > ANY (SELECT u2.id FROM Doctrine\Tests\Models\CMS\CmsUser u2 WHERE u2.name = u.name)');
Expand Down
14 changes: 14 additions & 0 deletions tests/Doctrine/Tests/ORM/Query/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,4 +602,18 @@ public function testGetQueryCacheDriverWithCacheExplicitlySet(): void

self::assertSame($cache, CacheAdapter::wrap($query->getQueryCacheDriver()));
}

public function testCustomJoinsAndWithKeywordDeprecated(): void
{
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/10978');

$this->entityManager->createQuery('SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.phonenumbers p WITH p.phonenumber = 123 WHERE u.id = 1')->getResult();
}

public function testNoFetchJoinsAndWithKeywordSupported(): void
{
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/10978');

$this->entityManager->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.phonenumbers p WITH p.phonenumber = 123 WHERE u.id = 1')->getResult();
}
}
Loading