[DDC-2324] mapOneToMany not working after upgrade to symfony2.1 Created: 28/Feb/13 Updated: 04/Mar/13 Resolved: 04/Mar/13 |
|
| Status: | Resolved |
| Project: | Doctrine 2 - ORM |
| Component/s: | ORM |
| Affects Version/s: | 2.3.2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Thomas Mayer | Assignee: | Benjamin Eberlei |
| Resolution: | Invalid | Votes: | 0 |
| Labels: | None | ||
| Environment: |
debian 6, php 5.4.10 |
||
| Description |
|
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.
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. |
| Comments |
| Comment by Marco Pivetta [ 28/Feb/13 ] |
|
Please validate the generated mappings with Doctrine\ORM\Tools\SchemaValidator.php |
| Comment by Thomas Mayer [ 28/Feb/13 ] |
|
Using symfony 2.0 and doctrine 2.2.2, after the mapOneToMany() mapping SchemaValidator returns 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() |
| Comment by Marco Pivetta [ 28/Feb/13 ] |
|
Thomas Mayer are you able to write a failing test case for this one? It may just be an undocumented BC break though. |
| Comment by Thomas Mayer [ 28/Feb/13 ] |
|
I will try to track it down to a smaller model for the test case. |
| Comment by Benjamin Eberlei [ 04/Mar/13 ] |
|
Changing the mapping of entities after loading from a driver is undefined behavior. |