DDC-2324: mapOneToMany not working after upgrade to symfony2.1 #2918

Closed
opened 2026-01-22 14:07:17 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 28, 2013).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user thomas303:

After updating to from symfony 2.0 to symfony 2.1, creating a new mapping did not work when using \Doctrine\ORM\Mapping\ClassMetadata::mapOneToMany().

The code used was:

        /*** @var $metadata \Doctrine\ORM\Mapping\ClassMetadata **/
        $metadata = $this->getDoctrine()->getEntityManager()->getClassMetadata('SecretSecretBundle:Deal');

        if (!array*key*exists('rolap', $metadata->getAssociationMappings())) {
            // use a temporary join mapping
            $metadata->mapOneToMany(array(
                'targetEntity' => 'Secret\SecretBundle\Entity\RolapDealP1m',
                'fieldName' => 'rolap',
                'mappedBy' => 'deal',
            ));
        }

A manyToOne mapping from RolapDealP1m to Deal was already created in the RolapDealP1m entity class.

Then, a query using the queryBuilder was created like this:

$qb=$repo->createQueryBuilder('Deal');
$qb
    ->join('Deal.rolap', 'Rolap')
[additional joins]
    ->select(
        array(
            'Deal.number number',
            'Deal.product productName',
[additional fields]
        )
    )
[additional where and group by]
;

The problem occurs, when doing a simple

$qb->getQuery()->getResult();

On symfony 2.0 using doctrine 2.2.2 it worked fine, the result was returned.
On symfony 2.1 using doctrine 2.3.2 and 2.2.2 an error occurs:

Notice: Undefined index: rolap in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php line 366

As a workaround, we added the OneToMany mapping to the Deal Entity instead of using a temporary mapping. This worked fine with symfony 2.1/doctrine 2.3.2.

We think there has been a regression when trying to create temporary mappings.

Originally created by @doctrinebot on GitHub (Feb 28, 2013). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user thomas303: After updating to from symfony 2.0 to symfony 2.1, creating a new mapping did not work when using \Doctrine\ORM\Mapping\ClassMetadata::mapOneToMany(). The code used was: ``` /*** @var $metadata \Doctrine\ORM\Mapping\ClassMetadata **/ $metadata = $this->getDoctrine()->getEntityManager()->getClassMetadata('SecretSecretBundle:Deal'); if (!array*key*exists('rolap', $metadata->getAssociationMappings())) { // use a temporary join mapping $metadata->mapOneToMany(array( 'targetEntity' => 'Secret\SecretBundle\Entity\RolapDealP1m', 'fieldName' => 'rolap', 'mappedBy' => 'deal', )); } ``` A manyToOne mapping from RolapDealP1m to Deal was already created in the RolapDealP1m entity class. Then, a query using the queryBuilder was created like this: ``` $qb=$repo->createQueryBuilder('Deal'); $qb ->join('Deal.rolap', 'Rolap') [additional joins] ->select( array( 'Deal.number number', 'Deal.product productName', [additional fields] ) ) [additional where and group by] ; ``` The problem occurs, when doing a simple ``` $qb->getQuery()->getResult(); ``` On symfony 2.0 using doctrine 2.2.2 it worked fine, the result was returned. On symfony 2.1 using doctrine 2.3.2 and 2.2.2 an error occurs: ``` Notice: Undefined index: rolap in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php line 366 ``` As a workaround, we added the OneToMany mapping to the Deal Entity instead of using a temporary mapping. This worked fine with symfony 2.1/doctrine 2.3.2. We think there has been a regression when trying to create temporary mappings.
admin added the Bug label 2026-01-22 14:07:17 +01:00
admin closed this issue 2026-01-22 14:07:17 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 28, 2013):

Comment created by @ocramius:

Please validate the generated mappings with Doctrine\ORM\Tools\SchemaValidator.php

@doctrinebot commented on GitHub (Feb 28, 2013): Comment created by @ocramius: Please validate the generated mappings with Doctrine\ORM\Tools\SchemaValidator.php
Author
Owner

@doctrinebot commented on GitHub (Feb 28, 2013):

Comment created by thomas303:

Using symfony 2.0 and doctrine 2.2.2, after the mapOneToMany() mapping SchemaValidator returns
'Secret\SecretBundle\Entity\Deal' =>
array (size=1)
0 => string 'The field Secret\SecretBundle\Entity\Deal#rolap is on the inverse side of a bi-directional relationship, but the specified mappedBy association on the target-entity Secret\SecretBundle\Entity\RolapDealP1m#deal does not contain the required 'inversedBy=rolap' attribute.' (length=271)

However, this works fine.

SchemaValidator returns the same when using symfony 2.1/doctrine 2.3.2, which is not working any more when doing the getResult()

@doctrinebot commented on GitHub (Feb 28, 2013): Comment created by thomas303: Using symfony 2.0 and doctrine 2.2.2, after the mapOneToMany() mapping SchemaValidator returns 'Secret\SecretBundle\Entity\Deal' => array (size=1) 0 => string 'The field Secret\SecretBundle\Entity\Deal#rolap is on the inverse side of a bi-directional relationship, but the specified mappedBy association on the target-entity Secret\SecretBundle\Entity\RolapDealP1m#deal does not contain the required 'inversedBy=rolap' attribute.' (length=271) However, this works fine. SchemaValidator returns the same when using symfony 2.1/doctrine 2.3.2, which is not working any more when doing the getResult()
Author
Owner

@doctrinebot commented on GitHub (Feb 28, 2013):

Comment created by @ocramius:

[~thomas303] are you able to write a failing test case for this one? It may just be an undocumented BC break though.

@doctrinebot commented on GitHub (Feb 28, 2013): Comment created by @ocramius: [~thomas303] are you able to write a failing test case for this one? It may just be an undocumented BC break though.
Author
Owner

@doctrinebot commented on GitHub (Feb 28, 2013):

Comment created by thomas303:

I will try to track it down to a smaller model for the test case.

@doctrinebot commented on GitHub (Feb 28, 2013): Comment created by thomas303: I will try to track it down to a smaller model for the test case.
Author
Owner

@doctrinebot commented on GitHub (Mar 4, 2013):

Comment created by @beberlei:

Changing the mapping of entities after loading from a driver is undefined behavior.

@doctrinebot commented on GitHub (Mar 4, 2013): Comment created by @beberlei: Changing the mapping of entities after loading from a driver is undefined behavior.
Author
Owner

@doctrinebot commented on GitHub (Mar 4, 2013):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Mar 4, 2013): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2918