Skip to content

Loading…

DDC-809: ArrayHydrator and ObjectHydrator return different result sets for the same query #5327

Closed
doctrinebot opened this Issue · 4 comments

2 participants

@doctrinebot

Jira issue originally created by user wizardz:

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);
@doctrinebot

Comment created by @beberlei:

Fixed formatting

@doctrinebot

Comment created by @beberlei:

Verified and updated priority, has to be in RC1

@doctrinebot

Comment created by @beberlei:

Fixed the issue, thank you very much for reporting :)

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0-RC1 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.