Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-809

ArrayHydrator and ObjectHydrator return different result sets for the same query

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA4
    • Fix Version/s: 2.0-RC1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Ubuntu 8.04.3, php 5.3.3, mysql 5.1

      Description

      I have many to many relation for 2 entities.

      ArrayHydrator and ObjectHydrator return different result sets for the same query. Because of some reasons ObjectHydrator mises 2 records.

      Code snippet and SQL to create database structure:

      CREATE TABLE IF NOT EXISTS `specification_value_test` (
        `specification_value_id` int(11) NOT NULL AUTO_INCREMENT,
        PRIMARY KEY (`specification_value_id`)
      ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=96058 ;
      
      INSERT INTO `specification_value_test` (`specification_value_id`) VALUES
      (94506),
      (94526),
      (94564),
      (94589),
      (94593),
      (94606),
      (94607),
      (94609),
      (94711),
      (94712),
      (94780);
      
      
      CREATE TABLE IF NOT EXISTS `variant_specification_value_test` (
        `variant_id` int(11) NOT NULL,
        `specification_value_id` int(11) NOT NULL,
        PRIMARY KEY (`variant_id`,`specification_value_id`),
        KEY `specification_value_id` (`specification_value_id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
      
      INSERT INTO `variant_specification_value_test` (`variant_id`, `specification_value_id`) VALUES
      (545208, 94506),
      (545209, 94506),
      (545208, 94526),
      (545209, 94526),
      (545208, 94564),
      (545209, 94564),
      (545209, 94589),
      (545209, 94593),
      (545208, 94606),
      (545209, 94606),
      (545208, 94607),
      (545209, 94607),
      (545208, 94609),
      (545209, 94609),
      (545208, 94711),
      (545208, 94712),
      (545208, 94780),
      (545209, 94780);
      
      CREATE TABLE IF NOT EXISTS `variant_test` (
        `variant_id` int(11) NOT NULL AUTO_INCREMENT,
        PRIMARY KEY (`variant_id`)
      ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT AUTO_INCREMENT=545210 ;
      
      INSERT INTO `variant_test` (`variant_id`) VALUES
      (545208),
      (545209);
      
      /**
       * @Table(name="variant_test")
       * @Entity
       */
      class Variant extends Base
      {
          /**
           * @Column(name="variant_id", type="integer")
           * @Id
           * @GeneratedValue(strategy="AUTO")
           */
          protected $variantId;
          
          /**
           * @ManyToMany(targetEntity="SpecificationValue", inversedBy="Variants")
           * @JoinTable(name="variant_specification_value_test",
           *   joinColumns={
           *     @JoinColumn(name="variant_id", referencedColumnName="variant_id")
           *   },
           *   inverseJoinColumns={
           *     @JoinColumn(name="specification_value_id", referencedColumnName="specification_value_id")
           *   }
           * )
           */
          protected $SpecificationValues;
      }
      
      /**
       * @Table(name="specification_value_test")
       * @Entity
       */
      class SpecificationValue
      {
          /**
           * @Column(name="specification_value_id", type="integer")
           * @Id
           * @GeneratedValue(strategy="AUTO")
           */
          protected $specificationValueId;
          
          /**
           * @var Variant
           *
           * @ManyToMany(targetEntity="Variant", mappedBy="SpecificationValues")
           */
          protected $Variants;
      }
      
      
      
      $result = $em->createQueryBuilder()
          ->select('Variant, SpecificationValue')
          ->from('Variant', 'Variant')
          ->leftJoin('Variant.SpecificationValues', 'SpecificationValue')
          ->getQuery()
          ->getResult();
      	
      // returns 9 specification values for first variant and 7 specification values for second variant
      \Doctrine\Common\Util\Debug($result, 4);
      
      $em->createQueryBuilder()
          ->select('Variant, SpecificationValue')
          ->from('Variant', 'Variant')
          ->leftJoin('Variant.SpecificationValues', 'SpecificationValue')
          ->getQuery()
          ->getArrayResult();
      
      // returns 9 specification values for first variant and 9 specification values for second variant
      \Doctrine\Common\Util\Debug($result);
      

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Fixed formatting

        Show
        Benjamin Eberlei added a comment - Fixed formatting
        Hide
        Benjamin Eberlei added a comment -

        Verified and updated priority, has to be in RC1

        Show
        Benjamin Eberlei added a comment - Verified and updated priority, has to be in RC1
        Hide
        Benjamin Eberlei added a comment -

        Fixed the issue, thank you very much for reporting

        Show
        Benjamin Eberlei added a comment - Fixed the issue, thank you very much for reporting

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Andriy Savchenko
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: