<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Thu May 23 09:17:12 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-357/DDC-357.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-357] Lazy-loading in OneToOne-bidirectional associations not working for inverse side</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-357</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;I am referring to the following situation: &lt;br/&gt;
&lt;a href=&quot;http://www.doctrine-project.org/documentation/manual/2_0/en/association-mapping#one-to-one,-bidirectional&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/documentation/manual/2_0/en/association-mapping#one-to-one,-bidirectional&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example: if I fetch an object of type &quot;Customer&quot; from my database, a second query is executed immediately that fetches the corresponding &quot;Cart&quot; even if I do not access the $cart property of &quot;Customer&quot;. Annotating fetch=&quot;LAZY&quot; to the $cart property does not make any difference. This is even worse in case of self-referencing objects, e.g. those having at most one parent object and at most one child object. Here, all associations are created by single database queries at once (e.g. fetching the child object, then the child of the child object and so forth).&lt;/p&gt;

&lt;p&gt;By contrast, OneToMany associations are lazy-loaded from the inverse side (as expected).&lt;/p&gt;

&lt;p&gt;Perhaps I should add, that I am using annotation mappings for my entities (no YAML, no XML). &lt;/p&gt;</description>
                <environment>XAMPP 1.7.3</environment>
            <key id="10926">DDC-357</key>
            <summary>Lazy-loading in OneToOne-bidirectional associations not working for inverse side</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="2">Won&apos;t Fix</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="m.walter">Marcel Walter</reporter>
                        <labels>
                    </labels>
                <created>Sun, 21 Feb 2010 10:07:31 +0000</created>
                <updated>Tue, 26 Feb 2013 16:41:16 +0000</updated>
                    <resolved>Sun, 21 Feb 2010 11:10:02 +0000</resolved>
                            <version>2.0-ALPHA4</version>
                                                <component>ORM</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>4</watches>
                        <comments>
                    <comment id="11778" author="romanb" created="Sun, 21 Feb 2010 11:09:50 +0000"  >&lt;p&gt;This is expected behavior. Inverse sides of one-to-one associations can not be lazy, technically. There is no foreign key on the inverse side, hence it is impossible to decide whether to proxy it or not. We must query for the associated object &lt;b&gt;or&lt;/b&gt; join it. Note that this only affects inverse sides of single-valued associations, that is, really only the inverse side of bidirectional one-to-one associations.&lt;/p&gt;

&lt;p&gt;In the future, you can use fetch=&quot;EAGER&quot; to automatically load the associated objects in a join whenever the inverse side object is loaded. That is a planned enhancement.&lt;br/&gt;
So when fetch=&quot;EAGER&quot; is used on a single-valued association, it is automatically fetch-joined, even when you just do -&amp;gt;find(&apos;Object&apos;, 1).&lt;/p&gt;

&lt;p&gt;Right now, you can use an eager fetch join in DQL to avoid the extra query. Fetch-joins on single-valued associated are usually very cheap, compared to collections.&lt;/p&gt;

&lt;p&gt;Note that you need a join anyway, because the foreign key is on the other side, thus it doesnt make much sense to join just for the sake of getting the foreign key. If we join we can as well grab the associated object completely.&lt;/p&gt;

&lt;p&gt;The &quot;fetch&quot; mode is a &quot;hint&quot;, that means, Doctrine tries to do that when possible. Its not always possible.&lt;/p&gt;

&lt;p&gt;If you have a suggestion, feel free to speak up.&lt;/p&gt;</comment>
                    <comment id="11779" author="romanb" created="Sun, 21 Feb 2010 11:36:45 +0000"  >&lt;p&gt;If you have an example of a self-referential association that causes extreme ripple-loading of the whole hierarchy, can you please file a new jira issue for that?&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;</comment>
                    <comment id="11780" author="romanb" created="Sun, 21 Feb 2010 11:37:51 +0000"  >&lt;p&gt;Here some other ways to get around the extra queries:&lt;/p&gt;

&lt;p&gt;1) $query-&amp;gt;setHint(Query::HINT_FORCE_PARTIAL_LOAD, true);&lt;/p&gt;

&lt;p&gt;2) $query-&amp;gt;getArrayResult() / -&amp;gt;getScalarResult()&lt;/p&gt;

&lt;p&gt;Just for the sake of completeness.&lt;/p&gt;</comment>
                    <comment id="17559" author="koc" created="Tue, 13 Mar 2012 12:16:42 +0000"  >&lt;p&gt;Why we cannot create proxy without FK?&lt;/p&gt;</comment>
                    <comment id="19114" author="naitsirch" created="Mon, 10 Dec 2012 09:27:21 +0000"  >&lt;p&gt;Hi. I have a problem with this solution.&lt;/p&gt;

&lt;p&gt;I have an entity &quot;Document&quot; with an one-to-one association to an entity called &quot;File&quot;. In the database table of the File entity I store the content of a file. So if I load for example 20 Documents I do not want the associated Files to be loaded, because this leads to memory problems.&lt;/p&gt;

&lt;p&gt;I do not understand the explanation &lt;blockquote&gt;&lt;p&gt;There is no foreign key on the inverse side, hence it is impossible to decide whether to proxy it or not.&lt;/p&gt;&lt;/blockquote&gt;&lt;br/&gt;
In a one-to-many association there is no foreign key on the inverse side, too. Why not always load a proxy like in a one-to-many association?&lt;/p&gt;

&lt;p&gt;Plus: There is no documentation about this, neither on &lt;a href=&quot;http://docs.doctrine-project.org/en/latest/reference/association-mapping.html&quot; class=&quot;external-link&quot;&gt;http://docs.doctrine-project.org/en/latest/reference/association-mapping.html&lt;/a&gt; nor &lt;a href=&quot;http://docs.doctrine-project.org/en/latest/reference/unitofwork-associations.html&quot; class=&quot;external-link&quot;&gt;http://docs.doctrine-project.org/en/latest/reference/unitofwork-associations.html&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="19116" author="romanb" created="Mon, 10 Dec 2012 10:25:22 +0000"  >&lt;p&gt;It is pretty simple, in a one-to-many association where the one-side is the inverse side, it holds a collection. The collection may be empty or not but there can always be a collection so it easy and correct to always put a proxy collection there.&lt;/p&gt;

&lt;p&gt;If you have a single-valued side that is the inverse side, how can you decide whether to put a proxy object there or not? Without seeing the foreign key you have no way to distinguish between: There is no associated object (and thus putting a proxy object in place would by simply wrong) or there is one and of which type it is, if inheritance is involved (since putting a proxy of the wrong type in is also wrong).&lt;/p&gt;

&lt;p&gt;This is as far as I recall, maybe Benjamin knows more on the current state.&lt;/p&gt;</comment>
                    <comment id="19117" author="naitsirch" created="Mon, 10 Dec 2012 10:42:53 +0000"  >&lt;p&gt;Okay, I see the problem. But it would be nice if this behaviour could be documented.&lt;/p&gt;

&lt;p&gt;Isn&apos;t it possible to always put a special proxy object there and if it get&apos;s accessed via lazy loading and Doctrine detect&apos;s that there is no associated entity, then the proxy will be replaced by a NULL value?&lt;/p&gt;</comment>
                    <comment id="19691" author="hrajchert" created="Tue, 26 Feb 2013 16:40:04 +0000"  >&lt;p&gt;Hi, I&apos;ve been faced with this issue some times. I tent to solve this by doing two unidirectional one-to-one. Then I deal with the non existing relationship using a method called getRelation that I defined in a BaseModel.&lt;br/&gt;
I have created this method because Doctrine filled up with a Proxy when I fetch the entity without its relationship (then accesing the object would throw an Exception), and filled up with null when the object was eagerly fetched (left join) but no relationship was found.&lt;br/&gt;
I think we could add this getRelation in the entitymanager or a trait after php 5.4.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="11415" name="getRelation.php" size="1694" author="hrajchert" created="Tue, 26 Feb 2013 16:40:04 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>