ObjectHydrator: fix entity namespaces. #614

Closed
wants to merge 4 commits into
from

3 participants

@jelmersnoeck

Object Hydrator: fix entity namespaces

If you are using Entity Namespace aliases, the ObjectHydrator will throw a notice for an undefined index of your entity namespace.

Problem

The problem lies in the fact that the prepare() method uses the "className", used in the aliasMap (where you use the namespace alias) to store the local ClassMetadata cache. Though, in a later stage the actual namespace is being used to find this same item.

Fix

I've changed the way this ClassMetadata cache is built. It now uses the full Entity namespace.

@doctrinebot

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-2350

@jelmersnoeck jelmersnoeck referenced this pull request in doctrine/DoctrineBundle Mar 14, 2013
Closed

ResultSetMapping #167

@stof stof commented on the diff Mar 14, 2013
lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
@@ -101,9 +101,10 @@ protected function prepare()
foreach ($this->_rsm->aliasMap as $dqlAlias => $className) {
$this->identifierMap[$dqlAlias] = array();
$this->idTemplate[$dqlAlias] = '';
+ $classMetadata = $this->_em->getClassMetadata($className);
@stof
Doctrine member
stof added a line comment Mar 14, 2013

This defeats the cache as you are always fetching it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Majkl578 Majkl578 commented on an outdated diff Mar 14, 2013
lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
- if ( ! isset($this->ce[$className])) {
- $this->ce[$className] = $this->_em->getClassMetadata($className);
+ if ( ! isset($this->ce[$classMetadata->name])) {
+ $this->ce[$classMetadata->name] = $this->_em->getClassMetadata($className);
@Majkl578
Majkl578 added a line comment Mar 14, 2013

You defined $classMetadata above, but now you refuse to use it and ask EM for them again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@beberlei
Doctrine member

This should be fixed as part of the SqlWalker process instead of in every hydration. This way this can be cached, the hydrator doesnt have to change. AFAIK this was done by another PR very recently.

@beberlei beberlei closed this May 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment