Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fix for DDC-1435 #159

Closed
wants to merge 1 commit into from

2 participants

Payam Hekmat Alexander
Payam Hekmat

Fix ClassMetadataInfo->getQuotedColumnName to correctly handle entity
FK as PK by looking for the field in association mappings in addition
to field mappings

Payam Hekmat Fix for DDC-1435
Fix ClassMetadataInfo->getQuotedColumnName to correctly handle entity
FK as PK by looking for the field in association mappings in addition
to field mappings
6702d13
Alexander
Collaborator
asm89 commented

This issue was fixed: http://www.doctrine-project.org/jira/browse/DDC-1435.

I tried to verify by running the test you added and it succeeded.

Alexander asm89 closed this
elHornair elHornair referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
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.

Oct 18, 2011
Payam Hekmat Fix for DDC-1435
Fix ClassMetadataInfo->getQuotedColumnName to correctly handle entity
FK as PK by looking for the field in association mappings in addition
to field mappings
6702d13
This page is out of date. Refresh to see the latest.
77  lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
@@ -119,7 +119,7 @@ class ClassMetadataInfo implements ClassMetadata
119 119
     const FETCH_LAZY = 2;
120 120
     /**
121 121
      * Specifies that an association is to be fetched when the owner of the
122  
-     * association is fetched. 
  122
+     * association is fetched.
123 123
      */
124 124
     const FETCH_EAGER = 3;
125 125
     /**
@@ -206,7 +206,7 @@ class ClassMetadataInfo implements ClassMetadata
206 206
 
207 207
     /**
208 208
      * READ-ONLY: The named queries allowed to be called directly from Repository.
209  
-     * 
  209
+     *
210 210
      * @var array
211 211
      */
212 212
     public $namedQueries = array();
@@ -361,7 +361,7 @@ class ClassMetadataInfo implements ClassMetadata
361 361
      * - <b>mappedBy</b> (string, required for bidirectional associations)
362 362
      * The name of the field that completes the bidirectional association on the owning side.
363 363
      * This key must be specified on the inverse side of a bidirectional association.
364  
-     * 
  364
+     *
365 365
      * - <b>inversedBy</b> (string, required for bidirectional associations)
366 366
      * The name of the field that completes the bidirectional association on the inverse side.
367 367
      * This key must be specified on the owning side of a bidirectional association.
@@ -388,7 +388,7 @@ class ClassMetadataInfo implements ClassMetadata
388 388
      * Specification of a field on target-entity that is used to index the collection by.
389 389
      * This field HAS to be either the primary key or a unique column. Otherwise the collection
390 390
      * does not contain all the entities that are actually related.
391  
-     * 
  391
+     *
392 392
      * A join table definition has the following structure:
393 393
      * <pre>
394 394
      * array(
@@ -430,7 +430,7 @@ class ClassMetadataInfo implements ClassMetadata
430 430
     /**
431 431
      * READ-ONLY: The definition of the sequence generator of this class. Only used for the
432 432
      * SEQUENCE generation strategy.
433  
-     * 
  433
+     *
434 434
      * The definition has the following structure:
435 435
      * <code>
436 436
      * array(
@@ -774,12 +774,12 @@ protected function _validateAndCompleteAssociationMapping(array $mapping)
774 774
         // If targetEntity is unqualified, assume it is in the same namespace as
775 775
         // the sourceEntity.
776 776
         $mapping['sourceEntity'] = $this->name;
777  
-        
  777
+
778 778
         if (isset($mapping['targetEntity'])) {
779 779
             if (strlen($this->namespace) > 0 && strpos($mapping['targetEntity'], '\\') === false) {
780 780
                 $mapping['targetEntity'] = $this->namespace . '\\' . $mapping['targetEntity'];
781 781
             }
782  
-            
  782
+
783 783
             $mapping['targetEntity'] = ltrim($mapping['targetEntity'], '\\');
784 784
         }
785 785
 
@@ -813,7 +813,7 @@ protected function _validateAndCompleteAssociationMapping(array $mapping)
813 813
         if ( ! isset($mapping['targetEntity'])) {
814 814
             throw MappingException::missingTargetEntity($mapping['fieldName']);
815 815
         }
816  
-        
  816
+
817 817
         // Mandatory and optional attributes for either side
818 818
         if ( ! $mapping['mappedBy']) {
819 819
             if (isset($mapping['joinTable']) && $mapping['joinTable']) {
@@ -829,7 +829,7 @@ protected function _validateAndCompleteAssociationMapping(array $mapping)
829 829
         if (isset($mapping['id']) && $mapping['id'] === true && $mapping['type'] & self::TO_MANY) {
830 830
             throw MappingException::illegalToManyIdentifierAssoaction($this->name, $mapping['fieldName']);
831 831
         }
832  
-        
  832
+
833 833
         // Fetch mode. Default fetch mode to LAZY, if not set.
834 834
         if ( ! isset($mapping['fetch'])) {
835 835
             $mapping['fetch'] = self::FETCH_LAZY;
@@ -837,18 +837,18 @@ protected function _validateAndCompleteAssociationMapping(array $mapping)
837 837
 
838 838
         // Cascades
839 839
         $cascades = isset($mapping['cascade']) ? array_map('strtolower', $mapping['cascade']) : array();
840  
-        
  840
+
841 841
         if (in_array('all', $cascades)) {
842 842
             $cascades = array('remove', 'persist', 'refresh', 'merge', 'detach');
843 843
         }
844  
-        
  844
+
845 845
         $mapping['cascade'] = $cascades;
846 846
         $mapping['isCascadeRemove'] = in_array('remove',  $cascades);
847 847
         $mapping['isCascadePersist'] = in_array('persist',  $cascades);
848 848
         $mapping['isCascadeRefresh'] = in_array('refresh',  $cascades);
849 849
         $mapping['isCascadeMerge'] = in_array('merge',  $cascades);
850 850
         $mapping['isCascadeDetach'] = in_array('detach',  $cascades);
851  
-        
  851
+
852 852
         return $mapping;
853 853
     }
854 854
 
@@ -862,11 +862,11 @@ protected function _validateAndCompleteAssociationMapping(array $mapping)
862 862
     protected function _validateAndCompleteOneToOneMapping(array $mapping)
863 863
     {
864 864
         $mapping = $this->_validateAndCompleteAssociationMapping($mapping);
865  
-        
  865
+
866 866
         if (isset($mapping['joinColumns']) && $mapping['joinColumns']) {
867 867
             $mapping['isOwningSide'] = true;
868 868
         }
869  
-        
  869
+
870 870
         if ($mapping['isOwningSide']) {
871 871
             if ( ! isset($mapping['joinColumns']) || ! $mapping['joinColumns']) {
872 872
                 // Apply default join column
@@ -933,7 +933,7 @@ protected function _validateAndCompleteOneToManyMapping(array $mapping)
933 933
         if ( ! isset($mapping['mappedBy'])) {
934 934
             throw MappingException::oneToManyRequiresMappedBy($mapping['fieldName']);
935 935
         }
936  
-        
  936
+
937 937
         $mapping['orphanRemoval']   = isset($mapping['orphanRemoval']) ? (bool) $mapping['orphanRemoval'] : false;
938 938
         $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] ? true : $mapping['isCascadeRemove'];
939 939
 
@@ -942,7 +942,7 @@ protected function _validateAndCompleteOneToManyMapping(array $mapping)
942 942
                 throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
943 943
             }
944 944
         }
945  
-        
  945
+
946 946
         return $mapping;
947 947
     }
948 948
 
@@ -960,7 +960,7 @@ protected function _validateAndCompleteManyToManyMapping(array $mapping)
960 960
             } else {
961 961
                 $targetShortName = strtolower($mapping['targetEntity']);
962 962
             }
963  
-            
  963
+
964 964
             // owning side MUST have a join table
965 965
             if ( ! isset($mapping['joinTable']['name'])) {
966 966
                 $mapping['joinTable']['name'] = $sourceShortName .'_' . $targetShortName;
@@ -1369,11 +1369,11 @@ public function setPrimaryTable(array $table)
1369 1369
                 $this->table['name'] = $table['name'];
1370 1370
             }
1371 1371
         }
1372  
-        
  1372
+
1373 1373
         if (isset($table['indexes'])) {
1374 1374
             $this->table['indexes'] = $table['indexes'];
1375 1375
         }
1376  
-        
  1376
+
1377 1377
         if (isset($table['uniqueConstraints'])) {
1378 1378
             $this->table['uniqueConstraints'] = $table['uniqueConstraints'];
1379 1379
         }
@@ -1522,7 +1522,7 @@ protected function _storeAssociationMapping(array $assocMapping)
1522 1522
      */
1523 1523
     public function setCustomRepositoryClass($repositoryClassName)
1524 1524
     {
1525  
-        if ($repositoryClassName !== null && strpos($repositoryClassName, '\\') === false 
  1525
+        if ($repositoryClassName !== null && strpos($repositoryClassName, '\\') === false
1526 1526
                 && strlen($this->namespace) > 0) {
1527 1527
             $repositoryClassName = $this->namespace . '\\' . $repositoryClassName;
1528 1528
         }
@@ -1722,7 +1722,7 @@ public function isAssociationWithSingleJoinColumn($fieldName)
1722 1722
 
1723 1723
     /**
1724 1724
      * Return the single association join column (if any).
1725  
-     * 
  1725
+     *
1726 1726
      * @param string $fieldName
1727 1727
      * @return string
1728 1728
      */
@@ -1764,7 +1764,7 @@ public function getFieldForColumn($columnName)
1764 1764
             foreach ($this->associationMappings AS $assocName => $mapping) {
1765 1765
                 if ($this->isAssociationWithSingleJoinColumn($assocName) &&
1766 1766
                     $this->associationMappings[$assocName]['joinColumns'][0]['name'] == $columnName) {
1767  
-                    
  1767
+
1768 1768
                     return $assocName;
1769 1769
                 }
1770 1770
             }
@@ -1854,34 +1854,34 @@ public function markReadOnly()
1854 1854
     {
1855 1855
         $this->isReadOnly = true;
1856 1856
     }
1857  
-    
  1857
+
1858 1858
     /**
1859 1859
      * A numerically indexed list of field names of this persistent class.
1860  
-     * 
  1860
+     *
1861 1861
      * This array includes identifier fields if present on this class.
1862  
-     * 
  1862
+     *
1863 1863
      * @return array
1864 1864
      */
1865 1865
     public function getFieldNames()
1866 1866
     {
1867 1867
         return array_keys($this->fieldMappings);
1868 1868
     }
1869  
-    
  1869
+
1870 1870
     /**
1871 1871
      * A numerically indexed list of association names of this persistent class.
1872  
-     * 
  1872
+     *
1873 1873
      * This array includes identifier associations if present on this class.
1874  
-     * 
  1874
+     *
1875 1875
      * @return array
1876 1876
      */
1877 1877
     public function getAssociationNames()
1878 1878
     {
1879 1879
         return array_keys($this->associationMappings);
1880 1880
     }
1881  
-    
  1881
+
1882 1882
     /**
1883 1883
      * Returns the target class name of the given association.
1884  
-     * 
  1884
+     *
1885 1885
      * @param string $assocName
1886 1886
      * @return string
1887 1887
      */
@@ -1890,13 +1890,13 @@ public function getAssociationTargetClass($assocName)
1890 1890
         if ( ! isset($this->associationMappings[$assocName])) {
1891 1891
             throw new \InvalidArgumentException("Association name expected, '" . $assocName ."' is not an association.");
1892 1892
         }
1893  
-        
  1893
+
1894 1894
         return $this->associationMappings[$assocName]['targetEntity'];
1895 1895
     }
1896  
-    
  1896
+
1897 1897
     /**
1898 1898
      * Get fully-qualified class name of this persistent class.
1899  
-     * 
  1899
+     *
1900 1900
      * @return string
1901 1901
      */
1902 1902
     public function getName()
@@ -1907,20 +1907,25 @@ public function getName()
1907 1907
     /**
1908 1908
      * Gets the (possibly quoted) column name of a mapped field for safe use
1909 1909
      * in an SQL statement.
1910  
-     * 
  1910
+     *
1911 1911
      * @param string $field
1912 1912
      * @param AbstractPlatform $platform
1913 1913
      * @return string
1914 1914
      */
1915 1915
     public function getQuotedColumnName($field, $platform)
1916 1916
     {
  1917
+        if (isset($this->associationMappings[$field])) {
  1918
+            // no composite pk as fk entity assumption:
  1919
+            $mapping = $this->associationMappings[$field]['joinColumns'][0];
  1920
+            return isset($mapping['quoted']) ? $platform->quoteIdentifier($mapping['name']) : $mapping['name'];
  1921
+        }
1917 1922
         return isset($this->fieldMappings[$field]['quoted']) ? $platform->quoteIdentifier($this->fieldMappings[$field]['columnName']) : $this->fieldMappings[$field]['columnName'];
1918 1923
     }
1919  
-    
  1924
+
1920 1925
     /**
1921 1926
      * Gets the (possibly quoted) primary table name of this class for safe use
1922 1927
      * in an SQL statement.
1923  
-     * 
  1928
+     *
1924 1929
      * @param AbstractPlatform $platform
1925 1930
      * @return string
1926 1931
      */
43  tests/Doctrine/Tests/Models/CMS/CmsArticleTag.php
... ...
@@ -0,0 +1,43 @@
  1
+<?php
  2
+
  3
+namespace Doctrine\Tests\Models\CMS;
  4
+
  5
+/**
  6
+ * @Entity
  7
+ * @Table(name="cms_article_tags")
  8
+ */
  9
+class CmsArticleTag
  10
+{
  11
+    /**
  12
+     * @Id
  13
+     * @Column(type="string", length=255)
  14
+     */
  15
+    private $tag;
  16
+
  17
+    /**
  18
+     * @Id
  19
+     * @ManyToOne(targetEntity="CmsArticle");
  20
+     */
  21
+    private $article;
  22
+
  23
+
  24
+    public function getTag()
  25
+    {
  26
+        return $this->tag;
  27
+    }
  28
+
  29
+    public function setTag($tag)
  30
+    {
  31
+        $this->tag = $tag;
  32
+    }
  33
+
  34
+    public function getArticle()
  35
+    {
  36
+        return $this->article;
  37
+    }
  38
+
  39
+    public function setArticle($article)
  40
+    {
  41
+        $this->article = $article;
  42
+    }
  43
+}
137  tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
@@ -17,11 +17,11 @@ protected function setUp()
17 17
 
18 18
     /**
19 19
      * Assert a valid SQL generation.
20  
-     * 
  20
+     *
21 21
      * @param string $dqlToBeTested
22 22
      * @param string $sqlToBeConfirmed
23 23
      * @param array $queryHints
24  
-     * @param array $queryParams 
  24
+     * @param array $queryParams
25 25
      */
26 26
     public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, array $queryHints = array(), array $queryParams = array())
27 27
     {
@@ -34,11 +34,11 @@ public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, array $qu
34 34
 
35 35
             $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
36 36
                   ->useQueryCache(false);
37  
-            
  37
+
38 38
             foreach ($queryHints AS $name => $value) {
39 39
                 $query->setHint($name, $value);
40 40
             }
41  
-            
  41
+
42 42
             parent::assertEquals($sqlToBeConfirmed, $query->getSQL());
43 43
             $query->free();
44 44
         } catch (\Exception $e) {
@@ -383,7 +383,7 @@ public function testSupportsInstanceOfExpressionsInWherePart()
383 383
             "SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr IN ('employee')"
384 384
         );
385 385
     }
386  
-    
  386
+
387 387
     public function testSupportsInstanceOfExpressionInWherePartWithMultipleValues()
388 388
     {
389 389
         $this->assertSqlGeneration(
@@ -391,7 +391,7 @@ public function testSupportsInstanceOfExpressionInWherePartWithMultipleValues()
391 391
             "SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr IN ('employee', 'manager')"
392 392
         );
393 393
     }
394  
-    
  394
+
395 395
     /**
396 396
      * @group DDC-1194
397 397
      */
@@ -402,7 +402,7 @@ public function testSupportsInstanceOfExpressionsInWherePartPrefixedSlash()
402 402
             "SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr IN ('employee')"
403 403
         );
404 404
     }
405  
-    
  405
+
406 406
     /**
407 407
      * @group DDC-1194
408 408
      */
@@ -608,6 +608,27 @@ public function testExistsExpressionInWhereCorrelatedSubqueryAssocCondition()
608 608
         );
609 609
     }
610 610
 
  611
+    /**
  612
+     * @group DDC-1435
  613
+     */
  614
+    public function testSubselectWithEntityForeignKeyInPrimaryKey()
  615
+    {
  616
+        $this->assertSqlGeneration(
  617
+            // DQL
  618
+            'SELECT DISTINCT art FROM Doctrine\Tests\Models\CMS\CmsArticle art
  619
+                WHERE EXISTS (
  620
+                    SELECT artTag
  621
+                    FROM Doctrine\Tests\Models\CMS\CmsArticleTag artTag
  622
+                    WHERE artTag.article = art)',
  623
+            // SQL
  624
+            'SELECT DISTINCT c0_.id AS id0, c0_.topic AS topic1, c0_.text AS text2, c0_.version AS version3 FROM cms_articles c0_'
  625
+                . ' WHERE EXISTS ('
  626
+                    . 'SELECT c1_.tag, c1_.article_id FROM cms_article_tags c1_ WHERE c1_.article_id = c0_.id'
  627
+                    . ')'
  628
+
  629
+        );
  630
+    }
  631
+
611 632
     public function testLimitFromQueryClass()
612 633
     {
613 634
         $q = $this->_em
@@ -686,7 +707,7 @@ public function testOrderByCollectionAssociationSize()
686 707
             "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (SELECT COUNT(*) FROM cms_articles c1_ WHERE c1_.user_id = c0_.id) AS sclr4 FROM cms_users c0_ ORDER BY sclr4 ASC"
687 708
         );
688 709
     }
689  
-    
  710
+
690 711
     public function testOrderBySupportsSingleValuedPathExpressionOwningSide()
691 712
     {
692 713
         $this->assertSqlGeneration(
@@ -694,7 +715,7 @@ public function testOrderBySupportsSingleValuedPathExpressionOwningSide()
694 715
             "SELECT c0_.id AS id0, c0_.topic AS topic1, c0_.text AS text2, c0_.version AS version3 FROM cms_articles c0_ ORDER BY c0_.user_id ASC"
695 716
         );
696 717
     }
697  
-    
  718
+
698 719
     /**
699 720
      * @expectedException Doctrine\ORM\Query\QueryException
700 721
      */
@@ -931,7 +952,7 @@ public function testGroupByIdentificationVariable()
931 952
             'SELECT c0_.id AS id0, c0_.name AS name1, count(c1_.id) AS sclr2 FROM cms_groups c0_ INNER JOIN cms_users_groups c2_ ON c0_.id = c2_.group_id INNER JOIN cms_users c1_ ON c1_.id = c2_.user_id GROUP BY c0_.id'
932 953
         );
933 954
     }
934  
-    
  955
+
935 956
     public function testCaseContainingNullIf()
936 957
     {
937 958
         $this->assertSqlGeneration(
@@ -939,7 +960,7 @@ public function testCaseContainingNullIf()
939 960
             'SELECT NULLIF(c0_.id, c0_.name) AS sclr0 FROM cms_groups c0_'
940 961
         );
941 962
     }
942  
-    
  963
+
943 964
     public function testCaseContainingCoalesce()
944 965
     {
945 966
         $this->assertSqlGeneration(
@@ -1009,244 +1030,244 @@ public function testSelectForeignKeyPKWithoutFields()
1009 1030
             "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"
1010 1031
         );
1011 1032
     }
1012  
-    
  1033
+
1013 1034
     public function testGeneralCaseWithSingleWhenClause()
1014 1035
     {
1015 1036
         $this->assertSqlGeneration(
1016  
-            "SELECT g.id, CASE WHEN ((g.id / 2) > 18) THEN 1 ELSE 0 END AS test FROM Doctrine\Tests\Models\CMS\CmsGroup g", 
  1037
+            "SELECT g.id, CASE WHEN ((g.id / 2) > 18) THEN 1 ELSE 0 END AS test FROM Doctrine\Tests\Models\CMS\CmsGroup g",
1017 1038
             "SELECT c0_.id AS id0, CASE WHEN (c0_.id / 2 > 18) THEN 1 ELSE 0 END AS sclr1 FROM cms_groups c0_"
1018 1039
         );
1019 1040
     }
1020  
-    
  1041
+
1021 1042
     public function testGeneralCaseWithMultipleWhenClause()
1022 1043
     {
1023 1044
         $this->assertSqlGeneration(
1024  
-            "SELECT g.id, CASE WHEN (g.id / 2 < 10) THEN 2 WHEN ((g.id / 2) > 20) THEN 1 ELSE 0 END AS test FROM Doctrine\Tests\Models\CMS\CmsGroup g", 
  1045
+            "SELECT g.id, CASE WHEN (g.id / 2 < 10) THEN 2 WHEN ((g.id / 2) > 20) THEN 1 ELSE 0 END AS test FROM Doctrine\Tests\Models\CMS\CmsGroup g",
1025 1046
             "SELECT c0_.id AS id0, CASE WHEN (c0_.id / 2 < 10) THEN 2 WHEN (c0_.id / 2 > 20) THEN 1 ELSE 0 END AS sclr1 FROM cms_groups c0_"
1026 1047
         );
1027 1048
     }
1028  
-    
  1049
+
1029 1050
     public function testSimpleCaseWithSingleWhenClause()
1030 1051
     {
1031 1052
         $this->assertSqlGeneration(
1032  
-            "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id = CASE g.name WHEN 'admin' THEN 1 ELSE 2 END", 
  1053
+            "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id = CASE g.name WHEN 'admin' THEN 1 ELSE 2 END",
1033 1054
             "SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id = CASE c0_.name WHEN admin THEN 1 ELSE 2 END"
1034 1055
         );
1035 1056
     }
1036  
-    
  1057
+
1037 1058
     public function testSimpleCaseWithMultipleWhenClause()
1038 1059
     {
1039 1060
         $this->assertSqlGeneration(
1040  
-            "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id = (CASE g.name WHEN 'admin' THEN 1 WHEN 'moderator' THEN 2 ELSE 3 END)", 
  1061
+            "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id = (CASE g.name WHEN 'admin' THEN 1 WHEN 'moderator' THEN 2 ELSE 3 END)",
1041 1062
             "SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id = CASE c0_.name WHEN admin THEN 1 WHEN moderator THEN 2 ELSE 3 END"
1042 1063
         );
1043 1064
     }
1044  
-    
  1065
+
1045 1066
     public function testGeneralCaseWithSingleWhenClauseInSubselect()
1046 1067
     {
1047 1068
         $this->assertSqlGeneration(
1048  
-            "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE WHEN ((g2.id / 2) > 18) THEN 2 ELSE 1 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)", 
  1069
+            "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE WHEN ((g2.id / 2) > 18) THEN 2 ELSE 1 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)",
1049 1070
             "SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE WHEN (c1_.id / 2 > 18) THEN 2 ELSE 1 END AS sclr2 FROM cms_groups c1_)"
1050 1071
         );
1051 1072
     }
1052  
-    
  1073
+
1053 1074
     public function testGeneralCaseWithMultipleWhenClauseInSubselect()
1054 1075
     {
1055 1076
         $this->assertSqlGeneration(
1056  
-            "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE WHEN (g.id / 2 < 10) THEN 3 WHEN ((g.id / 2) > 20) THEN 2 ELSE 1 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)", 
  1077
+            "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE WHEN (g.id / 2 < 10) THEN 3 WHEN ((g.id / 2) > 20) THEN 2 ELSE 1 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)",
1057 1078
             "SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE WHEN (c0_.id / 2 < 10) THEN 3 WHEN (c0_.id / 2 > 20) THEN 2 ELSE 1 END AS sclr2 FROM cms_groups c1_)"
1058 1079
         );
1059 1080
     }
1060  
-    
  1081
+
1061 1082
     public function testSimpleCaseWithSingleWhenClauseInSubselect()
1062 1083
     {
1063 1084
         $this->assertSqlGeneration(
1064  
-            "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE g2.name WHEN 'admin' THEN 1 ELSE 2 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)", 
  1085
+            "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE g2.name WHEN 'admin' THEN 1 ELSE 2 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)",
1065 1086
             "SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE c1_.name WHEN admin THEN 1 ELSE 2 END AS sclr2 FROM cms_groups c1_)"
1066 1087
         );
1067 1088
     }
1068  
-    
  1089
+
1069 1090
     public function testSimpleCaseWithMultipleWhenClauseInSubselect()
1070 1091
     {
1071 1092
         $this->assertSqlGeneration(
1072  
-            "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE g2.name WHEN 'admin' THEN 1 WHEN 'moderator' THEN 2 ELSE 3 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)", 
  1093
+            "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE g2.name WHEN 'admin' THEN 1 WHEN 'moderator' THEN 2 ELSE 3 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)",
1073 1094
             "SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE c1_.name WHEN admin THEN 1 WHEN moderator THEN 2 ELSE 3 END AS sclr2 FROM cms_groups c1_)"
1074 1095
         );
1075 1096
     }
1076  
-    
  1097
+
1077 1098
     /**
1078 1099
      * @group DDC-1339
1079 1100
      */
1080 1101
     public function testIdentityFunctionInSelectClause()
1081 1102
     {
1082 1103
         $this->assertSqlGeneration(
1083  
-            "SELECT IDENTITY(u.email) as email_id FROM Doctrine\Tests\Models\CMS\CmsUser u", 
  1104
+            "SELECT IDENTITY(u.email) as email_id FROM Doctrine\Tests\Models\CMS\CmsUser u",
1084 1105
             "SELECT c0_.email_id AS sclr0 FROM cms_users c0_"
1085 1106
         );
1086 1107
     }
1087  
-    
  1108
+
1088 1109
     /**
1089 1110
      * @group DDC-1339
1090 1111
      */
1091 1112
     public function testIdentityFunctionDoesNotAcceptStateField()
1092 1113
     {
1093 1114
         $this->assertInvalidSqlGeneration(
1094  
-            "SELECT IDENTITY(u.name) as name FROM Doctrine\Tests\Models\CMS\CmsUser u", 
  1115
+            "SELECT IDENTITY(u.name) as name FROM Doctrine\Tests\Models\CMS\CmsUser u",
1095 1116
             "Doctrine\ORM\Query\QueryException"
1096 1117
         );
1097 1118
     }
1098  
-    
  1119
+
1099 1120
     /**
1100 1121
      * @group DDC-1389
1101 1122
      */
1102 1123
     public function testInheritanceTypeJoinInRootClassWithDisabledForcePartialLoad()
1103 1124
     {
1104 1125
         $this->assertSqlGeneration(
1105  
-            'SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p', 
  1126
+            'SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p',
1106 1127
             'SELECT c0_.id AS id0, c0_.name AS name1, c1_.title AS title2, c1_.car_id AS car_id3, c2_.salary AS salary4, c2_.department AS department5, c2_.startDate AS startDate6, c0_.discr AS discr7, c0_.spouse_id AS spouse_id8 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id',
1107 1128
             array(Query::HINT_FORCE_PARTIAL_LOAD => false)
1108 1129
         );
1109 1130
     }
1110  
-    
  1131
+
1111 1132
     /**
1112 1133
      * @group DDC-1389
1113 1134
      */
1114 1135
     public function testInheritanceTypeJoinInRootClassWithEnabledForcePartialLoad()
1115 1136
     {
1116 1137
         $this->assertSqlGeneration(
1117  
-            'SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p', 
  1138
+            'SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p',
1118 1139
             'SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_',
1119 1140
             array(Query::HINT_FORCE_PARTIAL_LOAD => true)
1120 1141
         );
1121 1142
     }
1122  
-    
  1143
+
1123 1144
     /**
1124 1145
      * @group DDC-1389
1125 1146
      */
1126 1147
     public function testInheritanceTypeJoinInChildClassWithDisabledForcePartialLoad()
1127 1148
     {
1128 1149
         $this->assertSqlGeneration(
1129  
-            'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e', 
  1150
+            'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e',
1130 1151
             'SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c2_.title AS title5, c2_.car_id AS car_id6, c0_.discr AS discr7, c0_.spouse_id AS spouse_id8 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN company_managers c2_ ON c1_.id = c2_.id',
1131 1152
             array(Query::HINT_FORCE_PARTIAL_LOAD => false)
1132 1153
         );
1133 1154
     }
1134  
-    
  1155
+
1135 1156
     /**
1136 1157
      * @group DDC-1389
1137 1158
      */
1138 1159
     public function testInheritanceTypeJoinInChildClassWithEnabledForcePartialLoad()
1139 1160
     {
1140 1161
         $this->assertSqlGeneration(
1141  
-            'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e', 
  1162
+            'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e',
1142 1163
             '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',
1143 1164
             array(Query::HINT_FORCE_PARTIAL_LOAD => true)
1144 1165
         );
1145 1166
     }
1146  
-    
  1167
+
1147 1168
     /**
1148 1169
      * @group DDC-1389
1149 1170
      */
1150 1171
     public function testInheritanceTypeJoinInLeafClassWithDisabledForcePartialLoad()
1151 1172
     {
1152 1173
         $this->assertSqlGeneration(
1153  
-            'SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m', 
  1174
+            'SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m',
1154 1175
             'SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c2_.title AS title5, c0_.discr AS discr6, c0_.spouse_id AS spouse_id7, c2_.car_id AS car_id8 FROM company_managers c2_ INNER JOIN company_employees c1_ ON c2_.id = c1_.id INNER JOIN company_persons c0_ ON c2_.id = c0_.id',
1155 1176
             array(Query::HINT_FORCE_PARTIAL_LOAD => false)
1156 1177
         );
1157 1178
     }
1158  
-    
  1179
+
1159 1180
     /**
1160 1181
      * @group DDC-1389
1161 1182
      */
1162 1183
     public function testInheritanceTypeJoinInLeafClassWithEnabledForcePartialLoad()
1163 1184
     {
1164 1185
         $this->assertSqlGeneration(
1165  
-            'SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m', 
  1186
+            'SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m',
1166 1187
             'SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c2_.title AS title5, c0_.discr AS discr6 FROM company_managers c2_ INNER JOIN company_employees c1_ ON c2_.id = c1_.id INNER JOIN company_persons c0_ ON c2_.id = c0_.id',
1167 1188
             array(Query::HINT_FORCE_PARTIAL_LOAD => true)
1168 1189
         );
1169 1190
     }
1170  
-    
  1191
+
1171 1192
     /**
1172 1193
      * @group DDC-1389
1173 1194
      */
1174 1195
     public function testInheritanceTypeSingleTableInRootClassWithDisabledForcePartialLoad()
1175 1196
     {
1176 1197
         $this->assertSqlGeneration(
1177  
-            'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c', 
  1198
+            'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c',
1178 1199
             "SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.fixPrice AS fixPrice2, c0_.hoursWorked AS hoursWorked3, c0_.pricePerHour AS pricePerHour4, c0_.maxPrice AS maxPrice5, c0_.discr AS discr6, c0_.salesPerson_id AS salesPerson_id7 FROM company_contracts c0_ WHERE c0_.discr IN ('fix', 'flexible', 'flexultra')",
1179 1200
             array(Query::HINT_FORCE_PARTIAL_LOAD => false)
1180 1201
         );
1181 1202
     }
1182  
-    
  1203
+
1183 1204
     /**
1184 1205
      * @group DDC-1389
1185 1206
      */
1186 1207
     public function testInheritanceTypeSingleTableInRootClassWithEnabledForcePartialLoad()
1187 1208
     {
1188 1209
         $this->assertSqlGeneration(
1189  
-            'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c', 
  1210
+            'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c',
1190 1211
             "SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.fixPrice AS fixPrice2, c0_.hoursWorked AS hoursWorked3, c0_.pricePerHour AS pricePerHour4, c0_.maxPrice AS maxPrice5, c0_.discr AS discr6 FROM company_contracts c0_ WHERE c0_.discr IN ('fix', 'flexible', 'flexultra')",
1191 1212
             array(Query::HINT_FORCE_PARTIAL_LOAD => true)
1192 1213
         );
1193 1214
     }
1194  
-    
  1215
+
1195 1216
     /**
1196 1217
      * @group DDC-1389
1197 1218
      */
1198 1219
     public function testInheritanceTypeSingleTableInChildClassWithDisabledForcePartialLoad()
1199 1220
     {
1200 1221
         $this->assertSqlGeneration(
1201  
-            'SELECT fc FROM Doctrine\Tests\Models\Company\CompanyFlexContract fc', 
  1222
+            'SELECT fc FROM Doctrine\Tests\Models\Company\CompanyFlexContract fc',
1202 1223
             "SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.hoursWorked AS hoursWorked2, c0_.pricePerHour AS pricePerHour3, c0_.maxPrice AS maxPrice4, c0_.discr AS discr5, c0_.salesPerson_id AS salesPerson_id6 FROM company_contracts c0_ WHERE c0_.discr IN ('flexible', 'flexultra')",
1203 1224
             array(Query::HINT_FORCE_PARTIAL_LOAD => false)
1204 1225
         );
1205 1226
     }
1206  
-    
  1227
+
1207 1228
     /**
1208 1229
      * @group DDC-1389
1209 1230
      */
1210 1231
     public function testInheritanceTypeSingleTableInChildClassWithEnabledForcePartialLoad()
1211 1232
     {
1212 1233
         $this->assertSqlGeneration(
1213  
-            'SELECT fc FROM Doctrine\Tests\Models\Company\CompanyFlexContract fc', 
  1234
+            'SELECT fc FROM Doctrine\Tests\Models\Company\CompanyFlexContract fc',
1214 1235
             "SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.hoursWorked AS hoursWorked2, c0_.pricePerHour AS pricePerHour3, c0_.maxPrice AS maxPrice4, c0_.discr AS discr5 FROM company_contracts c0_ WHERE c0_.discr IN ('flexible', 'flexultra')",
1215 1236
             array(Query::HINT_FORCE_PARTIAL_LOAD => true)
1216 1237
         );
1217 1238
     }
1218  
-    
  1239
+
1219 1240
     /**
1220 1241
      * @group DDC-1389
1221 1242
      */
1222 1243
     public function testInheritanceTypeSingleTableInLeafClassWithDisabledForcePartialLoad()
1223 1244
     {
1224 1245
         $this->assertSqlGeneration(
1225  
-            'SELECT fuc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract fuc', 
  1246
+            'SELECT fuc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract fuc',
1226 1247
             "SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.hoursWorked AS hoursWorked2, c0_.pricePerHour AS pricePerHour3, c0_.maxPrice AS maxPrice4, c0_.discr AS discr5, c0_.salesPerson_id AS salesPerson_id6 FROM company_contracts c0_ WHERE c0_.discr IN ('flexultra')",
1227 1248
             array(Query::HINT_FORCE_PARTIAL_LOAD => false)
1228 1249
         );
1229 1250
     }
1230  
-    
  1251
+
1231 1252
     /**
1232 1253
      * @group DDC-1389
1233 1254
      */
1234 1255
     public function testInheritanceTypeSingleTableInLeafClassWithEnabledForcePartialLoad()
1235 1256
     {
1236 1257
         $this->assertSqlGeneration(
1237  
-            'SELECT fuc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract fuc', 
  1258
+            'SELECT fuc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract fuc',
1238 1259
             "SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.hoursWorked AS hoursWorked2, c0_.pricePerHour AS pricePerHour3, c0_.maxPrice AS maxPrice4, c0_.discr AS discr5 FROM company_contracts c0_ WHERE c0_.discr IN ('flexultra')",
1239 1260
             array(Query::HINT_FORCE_PARTIAL_LOAD => true)
1240 1261
         );
1241 1262
     }
1242  
-    
  1263
+
1243 1264
     /**
1244 1265
      * @group DDC-1161
1245 1266
      */
1246 1267
     public function testSelfReferenceWithOneToOneDoesNotDuplicateAlias()
1247 1268
     {
1248 1269
         $this->assertSqlGeneration(
1249  
-            'SELECT p, pp FROM Doctrine\Tests\Models\Company\CompanyPerson p JOIN p.spouse pp', 
  1270
+            'SELECT p, pp FROM Doctrine\Tests\Models\Company\CompanyPerson p JOIN p.spouse pp',
1250 1271
             "SELECT c0_.id AS id0, c0_.name AS name1, c1_.title AS title2, c1_.car_id AS car_id3, c2_.salary AS salary4, c2_.department AS department5, c2_.startDate AS startDate6, c3_.id AS id7, c3_.name AS name8, c4_.title AS title9, c4_.car_id AS car_id10, c5_.salary AS salary11, c5_.department AS department12, c5_.startDate AS startDate13, c0_.discr AS discr14, c0_.spouse_id AS spouse_id15, c3_.discr AS discr16, c3_.spouse_id AS spouse_id17 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id INNER JOIN company_persons c3_ ON c0_.spouse_id = c3_.id LEFT JOIN company_managers c4_ ON c3_.id = c4_.id LEFT JOIN company_employees c5_ ON c3_.id = c5_.id",
1251 1272
             array(Query::HINT_FORCE_PARTIAL_LOAD => false)
1252 1273
         );
@@ -1277,7 +1298,7 @@ public function parse(\Doctrine\ORM\Query\Parser $parser)
1277 1298
         $parser->match(\Doctrine\ORM\Query\Lexer::T_OPEN_PARENTHESIS);
1278 1299
 
1279 1300
         $this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression();
1280  
-        
  1301
+
1281 1302
         $parser->match(\Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS);
1282 1303
     }
1283 1304
 }
Commit_comment_tip

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.