Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.4
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None
    • Environment:
      Symfony 2.3.3, MSSQL 2008 R2

      Description

      Expected behaviour: get 5 countries in africa (and other continents with countries)
      Actual behaviour: getting 1 country in africa (and other continents with countries)

      // Schema:
      One Continent to Many Country
      (Continent is called Region in the schema)

      // DQL

      $query = $em->createQuery("
      	SELECT continent, country
      	FROM Geo:Continent continent
      	JOIN continent.countries country
      	ORDER BY continent.order ASC, country.name ASC
      ");
      

      // Filter

      <?php
      namespace MyVendor\MyBundle\DoctrineFilter;
      
      use Doctrine\ORM\Mapping\ClassMetaData,
          Doctrine\ORM\Query\Filter\SQLFilter;
      
      class VioCountryFilter extends SQLFilter {
      
      	public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) {
      		if ($targetEntity->name === 'MyVendor\Entity\Geo\Country') {
      			return $targetTableAlias . '.isVioLand = 1';
      		} else {
      			return '';
      		}
      	}
      }
      

      // Filter config (in Symfony 2.3) YAML

      doctrine:
          orm:
              entity_managers:
                  default:
                      filters:
                          vio_country:
                              class: MyVendor\MyBundle\DoctrineFilter\VioCountryFilter
                              enabled: true
      

      // Generated - SQL

      SELECT 
        r0_.id AS id0, 
        r0_.Region AS Region1, 
        r0_.Sort AS Sort2, 
        l1_.LandId AS LandId3, 
        l1_.IsVioLand AS IsVioLand4, 
        l1_.Max AS Max22, 
        l1_.Min AS Min23, 
        l1_.LandNaam AS LandNaam24, 
        l1_.Population AS Population29, 
        l1_.RegionId AS RegionId35 
      FROM 
        Region r0_ WITH (NOLOCK) 
        INNER JOIN Land l1_ ON r0_.id = l1_.RegionId 
        AND (l1_.isVioLand = 1) 
      ORDER BY 
        r0_.Sort ASC, 
        l1_.LandNaam ASC
      

      // Executed SQL in Management Studio:
      This is only displaying the 6th continent: Africa (do not show other continents)
      (Sort goes from 1 to 6)

      id0 Region1 Sort2 LandId3 IsVioLand4 Max22 Min23 LandNaam24 Population29 RegionId35
      1 Africa 6 5 1 24.0 13.0 Algeria 37762962 1
      1 Africa 6 6 1 27.0 17.0 Egypt 79392466 1
      1 Africa 6 10 1 23.0 13.0 Morocco 32059424 1
      1 Africa 6 14 1 22.0 12.0 South Africa 50586757 1
      1 Africa 6 13 1 24.0 15.0 Tunisia 10673800 1

      HAS 5 COUNTRIES IN AFRICA !!!

      // Dump = The actual behaviour

      $continents = $query->getResult();
      var_dump($continents[5]);
      

      (also made this dump shorter)

      class MyVendor\Entity\Geo\Continent#1290 (4) {
        protected $id =>
        int(1)
        protected $countries =>
        class Doctrine\ORM\PersistentCollection#1292 (9) {
          private $snapshot =>
          array(1) { // 				<-- HAS 1 COUNTRIES IN AFRICA !!!
            [0] =>
            class MyVendor\Entity\Geo\Country#1293 (38) {
              ...
            }
          }
          private $coll =>
          class Doctrine\Common\Collections\ArrayCollection#1291 (1) {
            private $_elements =>
            array(1) { // 				<-- HAS 1 COUNTRIES IN AFRICA !!!
              ...
            }
          }
        }
        protected $name =>
        string(6) "Africa"
        protected $order =>
        int(6)
      }
      

        Activity

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Flip
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: