[DDC-188] Collections are not hydrated properly Created: 02/Dec/09  Updated: 02/Dec/09  Resolved: 02/Dec/09

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Blocker
Reporter: Nico Kaiser Assignee: Roman S. Borschel
Resolution: Invalid Votes: 0
Labels: None


 Description   

The following example has User and Address entities, where User has many Addresses (ArrayCollection).

http://pastebin.com/f1f065cb0

$u = $em->find('Entity\User', $id);
$addresses = $u->getAddresses();
foreach ($addresses as $a) { }  // This line breaks!

The script runs until the foreach loop, then it breaks with a fatal error:

PHP Notice:  Undefined variable: owningAssoc in /home/kaiser/doctrine/doctrine/lib/Doctrine/ORM/Persist
ers/StandardEntityPersister.php on line 545
PHP Fatal error:  Uncaught exception 'Doctrine\ORM\ORMException' with message 'Unrecognized field: user
Id' in /home/kaiser/doctrine/doctrine/lib/Doctrine/ORM/ORMException.php:14
Stack trace:
#0 /home/kaiser/doctrine/doctrine/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php(660): Doctrin
e\ORM\ORMException::unrecognizedField('userId')
#1 /home/kaiser/doctrine/doctrine/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php(545): Doctrin
e\ORM\Persisters\StandardEntityPersister->_getSelectEntitiesSql(Array, NULL)
#2 /home/kaiser/doctrine/doctrine/lib/Doctrine/ORM/Mapping/OneToManyMapping.php(133): Doctrine\ORM\Pers
isters\StandardEntityPersister->loadOneToManyCollection(Array, Object(Doctrine\ORM\PersistentCollection
))
#3 /home/kaiser/doctrine/doctrine/lib/Doctrine/ORM/PersistentCollection.php(244): Doctrine\ORM\Mapping\
OneToManyMapping->load(Object(Entity\User), Object(Doctrine\ORM\PersistentCollection), Object(Doctrine\
ORM\EntityManager))
#4 /home/kaiser/doctrine/doctrine/lib/Doctrine/ORM/PersistentCollection.php(549): Doc in /home/kaiser/d
octrine/doctrine/lib/Doctrine/ORM/ORMException.php on line 14

If I uncomment the user creation code in my pastebin example (i.e. create User, Address first), it works as expected (assumingly because everything is in the EM already).

So this bug probably breaks all select-only use cases with collections (which makes it a Blocker in my opinion).



 Comments   
Comment by Roman S. Borschel [ 02/Dec/09 ]

Hm, this is dubious as this is directly and indirectly tested all over the place.

I was unable to reproduce it as of yet. Will keep you updated.

Comment by Roman S. Borschel [ 02/Dec/09 ]

Are you sure you dont have local modifications? The notice looks suspicious and _getSelectEntitiesSql(Array, NULL) does not look correct either. The association should be passed in.

Comment by Roman S. Borschel [ 02/Dec/09 ]

Your patch in DDC-162 is what breaks it.

Generated at Sat Jul 26 17:20:31 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.