Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[INVALID] [DDC-2452] DQL arbitrary joins between JTI entities produces invalid SQL #668

Closed
wants to merge 2 commits into from

3 participants

Marco Pivetta Guilherme Blanco Matt Janssen
Marco Pivetta
Collaborator

DDC-2452 - DQL joins between JTI entities produce invalid SQL when additional conditions are inserted via WITH clause

Still working on a fix

Ocramius added some commits
Marco Pivetta Ocramius Adding failing test for DDC-2452
DQL joins between JTI entities produce invalid SQL when additional conditions are inserted via WITH clause
8453cb5
Marco Pivetta Ocramius Applying hotfix for DDC-2452 4e1450b
Guilherme Blanco
Owner

@Ocramius this seems to be an issue that precedence of joins would fix it

Marco Pivetta
Collaborator

@guilhermeblanco you mean #656? No, that doesn't fix this one (already tried pulling it locally)

Marco Pivetta
Collaborator

@guilhermeblanco indeed the fix seems to be invalid - this fixes the tests in SQLite platform, but breaks on MySQL platform...

Marco Pivetta
Collaborator

Closing since the fix is invalid and I cannot come up with something better right now

Marco Pivetta Ocramius closed this
Matt Janssen

Does #708 take care of this exact issue?

Marco Pivetta
Collaborator

@mattjanssen not really, the problem here is that the ON keyword was produced twice in SQLite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

May 16, 2013
Marco Pivetta Ocramius Adding failing test for DDC-2452
DQL joins between JTI entities produce invalid SQL when additional conditions are inserted via WITH clause
8453cb5
Marco Pivetta Ocramius Applying hotfix for DDC-2452 4e1450b
This page is out of date. Refresh to see the latest.
2  lib/Doctrine/ORM/Query/SqlWalker.php
@@ -1029,7 +1029,7 @@ public function walkJoin($join)
1029 1029 switch (true) {
1030 1030 case ($joinDeclaration instanceof \Doctrine\ORM\Query\AST\RangeVariableDeclaration):
1031 1031 $class = $this->em->getClassMetadata($joinDeclaration->abstractSchemaName);
1032   - $condExprConjunction = $class->isInheritanceTypeJoined() && $joinType != AST\Join::JOIN_TYPE_LEFT && $joinType != AST\Join::JOIN_TYPE_LEFTOUTER
  1032 + $condExprConjunction = $class->isInheritanceTypeJoined()
1033 1033 ? ' AND '
1034 1034 : ' ON ';
1035 1035
71 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2452Test.php
... ... @@ -0,0 +1,71 @@
  1 +<?php
  2 +/*
  3 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14 + *
  15 + * This software consists of voluntary contributions made by many individuals
  16 + * and is licensed under the MIT license. For more information, see
  17 + * <http://www.doctrine-project.org>.
  18 + */
  19 +
  20 +namespace Doctrine\Tests\ORM\Functional\Ticket;
  21 +
  22 +/**
  23 + * @group DDC-2452
  24 + *
  25 + * @author Marco Pivetta <ocramius@gmail.com>
  26 + */
  27 +class DDC2452Test extends \Doctrine\Tests\OrmFunctionalTestCase
  28 +{
  29 + public function testTicket()
  30 + {
  31 + if ($this->_em->getConnection()->getDatabasePlatform()->getName() != 'sqlite') {
  32 + // @todo set the abstract platform?
  33 + $this->markTestSkipped("This test is useful for all databases, but designed only for mysql.");
  34 + }
  35 +
  36 + $dql = 'SELECT foo1 FROM '
  37 + . __NAMESPACE__ . '\DDC2452Foo foo1'
  38 + . ' LEFT JOIN '
  39 + . __NAMESPACE__ . '\DDC2452Foo foo2'
  40 + . ' WITH 1 = 1';
  41 +
  42 + $sql = $this->_em->createQuery($dql)->getSQL();
  43 +
  44 + $this->assertStringMatchesFormat(
  45 + 'SELECT %s FROM %s LEFT JOIN %s ON %s LEFT JOIN %s LEFT JOIN %s ON %s = %s AND (1 = 1)',
  46 + $sql,
  47 + 'The generated SQL adds conditions defined in `WITH` to the existing SQL joins produced by the inheritance'
  48 + );
  49 + }
  50 +}
  51 +
  52 +/**
  53 + * @Entity
  54 + * @Table(name="foo")
  55 + * @InheritanceType("JOINED")
  56 + * @DiscriminatorColumn(name="discr", type="string")
  57 + * @DiscriminatorMap({"foo" = "DDC2452Foo", "bar" = "DDC2452Bar"})
  58 + */
  59 +class DDC2452Foo
  60 +{
  61 + /** @Id @Column(type="integer") @GeneratedValue */
  62 + public $id;
  63 +}
  64 +
  65 +/**
  66 + * @Entity
  67 + * @Table(name="bar")
  68 + */
  69 +class DDC2452Bar extends DDC2452Foo
  70 +{
  71 +}
2  tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
@@ -160,7 +160,7 @@ public function testSupportsJoinOnMultipleComponentsWithJoinedInheritanceType()
160 160
161 161 $this->assertSqlGeneration(
162 162 'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e LEFT JOIN Doctrine\Tests\Models\Company\CompanyManager m WITH e.id = m.id',
163   - 'SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c0_.discr AS discr5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN company_managers c2_ INNER JOIN company_employees c3_ ON c2_.id = c3_.id INNER JOIN company_persons c4_ ON c2_.id = c4_.id ON (c0_.id = c4_.id)'
  163 + 'SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c0_.discr AS discr5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN company_managers c2_ INNER JOIN company_employees c3_ ON c2_.id = c3_.id INNER JOIN company_persons c4_ ON c2_.id = c4_.id AND (c0_.id = c4_.id)'
164 164 );
165 165 }
166 166

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.