Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[DDC-1652] Fix SqlWalker to include foreign key identifiers in SQL SELEC... #290

Merged
merged 1 commit into from over 2 years ago

2 participants

Benjamin Eberlei Guilherme Blanco
Benjamin Eberlei
Owner

...T statement no matter what the meta column setting is suggesting.

Benjamin Eberlei beberlei [DDC-1652] Fix SqlWalker to include foreign key identifiers in SQL SE…
…LECT statement no matter what the meta column setting is suggesting.
1bbd52b
Guilherme Blanco guilhermeblanco merged commit 55a9e1e into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 20, 2012
Benjamin Eberlei beberlei [DDC-1652] Fix SqlWalker to include foreign key identifiers in SQL SE…
…LECT statement no matter what the meta column setting is suggesting.
1bbd52b
This page is out of date. Refresh to see the latest.
2  lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
@@ -234,7 +234,7 @@ protected function gatherRowData(array $data, array &$cache, array &$id, array &
234 234
235 235 if (isset($cache[$key]['isScalar'])) {
236 236 $value = $cache[$key]['type']->convertToPHPValue($value, $this->_platform);
237   -
  237 +
238 238 $rowData['scalars'][$cache[$key]['fieldName']] = $value;
239 239
240 240 continue;
2  lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php
@@ -286,4 +286,4 @@ private function getClassMetadata($className)
286 286
287 287 return $this->_ce[$className];
288 288 }
289   -}
  289 +}
15 lib/Doctrine/ORM/Query/SqlWalker.php
@@ -636,11 +636,17 @@ public function walkSelectClause($selectClause)
636 636 }
637 637
638 638 // Add foreign key columns to SQL, if necessary
639   - if ( ! $addMetaColumns) continue;
  639 + if ( ! $addMetaColumns && ! $class->containsForeignIdentifier) {
  640 + continue;
  641 + }
640 642
641 643 // Add foreign key columns of class and also parent classes
642 644 foreach ($class->associationMappings as $assoc) {
643   - if ( ! ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) continue;
  645 + if ( ! ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) {
  646 + continue;
  647 + } else if ( !$addMetaColumns && !isset($assoc['id'])) {
  648 + continue;
  649 + }
644 650
645 651 $owningClass = (isset($assoc['inherited'])) ? $this->_em->getClassMetadata($assoc['inherited']) : $class;
646 652 $sqlTableAlias = $this->getSQLTableAlias($owningClass->getTableName(), $dqlAlias);
@@ -654,6 +660,11 @@ public function walkSelectClause($selectClause)
654 660 }
655 661 }
656 662
  663 + // Add foreign key columns to SQL, if necessary
  664 + if ( ! $addMetaColumns) {
  665 + continue;
  666 + }
  667 +
657 668 // Add foreign key columns of subclasses
658 669 foreach ($class->subClasses as $subClassName) {
659 670 $subClass = $this->_em->getClassMetadata($subClassName);
28 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php
@@ -433,4 +433,32 @@ public function testMergeForeignKeyIdentifierEntity()
433 433 $this->assertEquals($this->article1->id(), $refRep->source()->id());
434 434 $this->assertEquals($this->article2->id(), $refRep->target()->id());
435 435 }
  436 +
  437 + /**
  438 + * @group DDC-1652
  439 + */
  440 + public function testArrayHydrationWithCompositeKey()
  441 + {
  442 + $dql = "SELECT r,s,t FROM Doctrine\Tests\Models\DDC117\DDC117Reference r INNER JOIN r.source s INNER JOIN r.target t";
  443 + $before = count($this->_em->createQuery($dql)->getResult());
  444 +
  445 + $this->article1 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article1->id());
  446 + $this->article2 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article2->id());
  447 +
  448 + $this->reference = new DDC117Reference($this->article2, $this->article1, "Test-Description");
  449 + $this->_em->persist($this->reference);
  450 +
  451 + $this->reference = new DDC117Reference($this->article1, $this->article1, "Test-Description");
  452 + $this->_em->persist($this->reference);
  453 +
  454 + $this->reference = new DDC117Reference($this->article2, $this->article2, "Test-Description");
  455 + $this->_em->persist($this->reference);
  456 +
  457 + $this->_em->flush();
  458 +
  459 + $dql = "SELECT r,s,t FROM Doctrine\Tests\Models\DDC117\DDC117Reference r INNER JOIN r.source s INNER JOIN r.target t";
  460 + $data = $this->_em->createQuery($dql)->getArrayResult();
  461 +
  462 + $this->assertEquals($before + 3, count($data));
  463 + }
436 464 }
2  tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
@@ -1074,7 +1074,7 @@ public function testSelectForeignKeyPKWithoutFields()
1074 1074 {
1075 1075 $this->assertSqlGeneration(
1076 1076 "SELECT t, s, l FROM Doctrine\Tests\Models\DDC117\DDC117Link l INNER JOIN l.target t INNER JOIN l.source s",
1077   - "SELECT d0_.article_id AS article_id0, d0_.title AS title1, d1_.article_id AS article_id2, d1_.title AS title3 FROM DDC117Link d2_ INNER JOIN DDC117Article d0_ ON d2_.target_id = d0_.article_id INNER JOIN DDC117Article d1_ ON d2_.source_id = d1_.article_id"
  1077 + "SELECT d0_.article_id AS article_id0, d0_.title AS title1, d1_.article_id AS article_id2, d1_.title AS title3, d2_.source_id AS source_id4, d2_.target_id AS target_id5 FROM DDC117Link d2_ INNER JOIN DDC117Article d0_ ON d2_.target_id = d0_.article_id INNER JOIN DDC117Article d1_ ON d2_.source_id = d1_.article_id"
1078 1078 );
1079 1079 }
1080 1080

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.