<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Sat May 25 18:42:00 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DDC-2306/DDC-2306.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DDC-2306] Lazy loading associated entity&apos;s property causes identity loss when another association is set to fetch=&quot;EAGER&quot;</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-2306</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;There appears to be a bug in UnitOfWork.php, introduced in &lt;a href=&quot;https://github.com/doctrine/doctrine2/commit/afee16e56bae9bfe93c96ef1398f077e534962a0#L9R2473&quot; class=&quot;external-link&quot;&gt;Merge pull request #406 from Ocramius/DCOM-96&lt;/a&gt;. The relevant section is lines 2479-2495.&lt;/p&gt;

&lt;p&gt;In the attached test sandbox, there are 4 entities. &lt;/p&gt;

&lt;p&gt;User and Address have a many-many relationship via UserAddress &amp;#8211; this more or less duplicates what I have in my actual application. There is another entity that both User and Address refer to in a one-to-many relationship &amp;#8211; Zone. &lt;/p&gt;

&lt;p&gt;When the Zone relationship on User and Address is set to fetch=&quot;LAZY&quot;, the problem is absent. When the relationship is set to fetch=&quot;EAGER&quot;, the problem manifests as such:&lt;/p&gt;

&lt;p&gt;When I load a User via $em-&amp;gt;find(), and then access properties on a related Address, the identity of the Address is lost. The same is true going in the other direction. I var_dump the Address before accessing its street property, and it shows up properly as an uninitialized proxy with just the id set. After I access the street property of the Address, var_dump shows the proxy is loaded and initialized, with all properties set &lt;em&gt;except&lt;/em&gt; the identity, which is now null.&lt;/p&gt;

&lt;p&gt;I stepped through the code using XDebug, and found that the referenced lines in UnitOfWork.php are setting the created Address entity&apos;s properties incorrectly, removing the identity from the generated entity. It seems to have something to do with the _hints parameter. &lt;/p&gt;

&lt;p&gt;I&apos;m not sure what the fix is, because I am not familiar enough with this part of the code and what it is intended to do. I assume that this is not intended behavior.&lt;/p&gt;

&lt;p&gt;I&apos;ve included my test case sandbox, which references ../../../../autoload.php to load Doctrine. This was tested against doctrine2/master as of today.&lt;/p&gt;</description>
                <environment>PHP 5.4 - IIS 7.0</environment>
            <key id="14506">DDC-2306</key>
            <summary>Lazy loading associated entity&apos;s property causes identity loss when another association is set to fetch=&quot;EAGER&quot;</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="2" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/critical.png">Critical</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                    <security id="10000">All</security>
                        <assignee username="ocramius">Marco Pivetta</assignee>
                                <reporter username="wschalle">William Schaller</reporter>
                        <labels>
                        <label>orm</label>
                        <label>proxy</label>
                        <label>unitofwork</label>
                    </labels>
                <created>Wed, 20 Feb 2013 05:40:54 +0000</created>
                <updated>Tue, 26 Feb 2013 08:27:25 +0000</updated>
                    <resolved>Tue, 26 Feb 2013 08:27:25 +0000</resolved>
                            <version>Git Master</version>
                                <fixVersion>2.4</fixVersion>
                                <component>ORM</component>
                        <due>Fri, 22 Feb 2013 00:00:00 +0000</due>
                    <votes>0</votes>
                        <watches>3</watches>
                        <comments>
                    <comment id="19573" author="ocramius" created="Thu, 21 Feb 2013 01:29:19 +0000"  >&lt;p&gt;I&apos;ve created a branch with a fix at &lt;a href=&quot;https://github.com/Ocramius/doctrine2/compare/hotfix;DDC-2306&quot; class=&quot;external-link&quot;&gt;https://github.com/Ocramius/doctrine2/compare/hotfix;DDC-2306&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically, what was happening here is a really nasty one: &lt;/p&gt;

&lt;p&gt;The UnitOfWork did consider the `Zone` entity as if it was a `User` entity (not comparing classnames, basically). Since the identifier was also the same in this case, the two entities were compared as if the newly loaded `Zone` had to replace the existing `User` proxy.&lt;/p&gt;

&lt;p&gt;Thus, the proxy was marked as un-managed and trashed (and so the identifier was also nulled).&lt;/p&gt;

&lt;p&gt;Please pull the branch and give it a try. I&apos;ll re-read it tomorrow and then open a PR.&lt;/p&gt;</comment>
                    <comment id="19574" author="wschalle" created="Thu, 21 Feb 2013 04:10:27 +0000"  >&lt;p&gt;This fixes the problem for the test case and for my app. Excellent speedy fix, thanks &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                    <comment id="19575" author="beberlei" created="Thu, 21 Feb 2013 08:36:52 +0000"  >&lt;p&gt;A related Github Pull-Request &lt;span class=&quot;error&quot;&gt;&amp;#91;GH-585&amp;#93;&lt;/span&gt; was opened&lt;br/&gt;
&lt;a href=&quot;https://github.com/doctrine/doctrine2/pull/585&quot; class=&quot;external-link&quot;&gt;https://github.com/doctrine/doctrine2/pull/585&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="19685" author="beberlei" created="Tue, 26 Feb 2013 05:55:52 +0000"  >&lt;p&gt;A related Github Pull-Request &lt;span class=&quot;error&quot;&gt;&amp;#91;GH-585&amp;#93;&lt;/span&gt; was closed&lt;br/&gt;
&lt;a href=&quot;https://github.com/doctrine/doctrine2/pull/585&quot; class=&quot;external-link&quot;&gt;https://github.com/doctrine/doctrine2/pull/585&lt;/a&gt;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="11379" name="sandbox-uow-issue.zip" size="11305" author="wschalle" created="Wed, 20 Feb 2013 05:40:54 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>