<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Mon May 20 03:36:41 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-1397/DDC-1397.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-1397] Accesing a OneToMany relation with Child Classes and OneToOne relations.</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-1397</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;I am facing a small issue on Doctrine 2 that causes OneToOne relation needed to be part of the parent class. The error occurs when doing $content-&amp;gt;getVersions() but not when doing $em-&amp;gt;find(&quot;Model\Lantern\Content\Version&quot;, $id). The error message is:&lt;/p&gt;


&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;Warning: Undefined index: summary in ORM/UnitOfWork.php:2012
Fatal error: Call to a member function setValue() on a non-object in ORM/UnitOfWork.php on line 2013
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Error replication:&lt;/p&gt;

&lt;p&gt;Simply by having a look at the model we can see what&apos;s causing the Bug, will avoid class annotations to make it simpler:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;class Content{
    /**
    * @OneToMany(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;Version&quot;&lt;/span&gt;, mappedBy=&lt;span class=&quot;code-quote&quot;&gt;&quot;content&quot;&lt;/span&gt;)
    */
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $versions;
...
}

class Version{
    /**
     * @ManyToOne(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;Content&quot;&lt;/span&gt;, inversedBy=&lt;span class=&quot;code-quote&quot;&gt;&quot;versions&quot;&lt;/span&gt;)
     * @JoinColumn(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;content_id&quot;&lt;/span&gt;, referencedColumnName=&lt;span class=&quot;code-quote&quot;&gt;&quot;content_id&quot;&lt;/span&gt;)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $content;
...
}

class Article &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; Version{
    /** @OneToOne(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;Model\Lantern\Content\Fieldset\Summary&quot;&lt;/span&gt;, mappedBy=&lt;span class=&quot;code-quote&quot;&gt;&quot;version&quot;&lt;/span&gt;, cascade={&lt;span class=&quot;code-quote&quot;&gt;&quot;persist&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;delete&quot;&lt;/span&gt;}) */
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $summary;  
...
}

class Summary{
    /**
     * @OneToOne(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;Model\Lantern\Content\Version&quot;&lt;/span&gt;, inversedBy=&lt;span class=&quot;code-quote&quot;&gt;&quot;summary&quot;&lt;/span&gt;)
     * @JoinColumn(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;version_id&quot;&lt;/span&gt;, referencedColumnName=&lt;span class=&quot;code-quote&quot;&gt;&quot;version_id&quot;&lt;/span&gt;)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $version;    
...
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As you can see, Article::$summary targets Summary::$version, but Summary::$version targets Version::$summary. This in OOP is valid as Version is contained inside Article, so doing a downcasting will get Article::summary.&lt;/p&gt;

&lt;p&gt;The reason I believe why using $em-&amp;gt;find works is that $em-&amp;gt;find already knows which child class is before doing map, and relations works fine.&lt;br/&gt;
On the other hand, when doing $content-&amp;gt;getVersions(), Content::$versions targets Version, and looks like Doctrine does not resolve which child class it before mapping OneToOne relationshipg.&lt;/p&gt;

&lt;p&gt;This bug doesn&apos;t occur with OneToMany or ManyToMany relationships.&lt;/p&gt;</description>
                <environment>Ubuntu 10.10 64bit&lt;br/&gt;
PHP 5.3.3&lt;br/&gt;
MySQL 5.1.49&lt;br/&gt;
Doctrine 2.1.2</environment>
            <key id="13051">DDC-1397</key>
            <summary>Accesing a OneToMany relation with Child Classes and OneToOne relations.</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="6">Invalid</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="gbrunacci">Gabriel Brunacci</reporter>
                        <labels>
                    </labels>
                <created>Thu, 29 Sep 2011 15:18:00 +0000</created>
                <updated>Sat, 15 Oct 2011 17:19:41 +0000</updated>
                    <resolved>Sat, 15 Oct 2011 17:19:41 +0000</resolved>
                            <version>2.1</version>
                <version>2.1.1</version>
                <version>2.1.2</version>
                                <fixVersion>2.1.2</fixVersion>
                                <component>ORM</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="16536" author="gbrunacci" created="Thu, 29 Sep 2011 15:20:16 +0000"  >&lt;p&gt;A side but useful note: when I move @OneToOne relation to the parent class Version, The error doesn&apos;t happen.&lt;/p&gt;</comment>
                    <comment id="16546" author="guilhermeblanco" created="Tue, 4 Oct 2011 04:37:25 +0000"  >&lt;p&gt;Should be the Summary::$version pointing to Article::$summary.&lt;/p&gt;

&lt;p&gt;Your mapping is wrong conceptually in OOP, because you&apos;re referring a non-existing property of Version ($summary is only part of Article).&lt;br/&gt;
Please fix the issue and check out if the error still persist.&lt;/p&gt;</comment>
                    <comment id="16607" author="beberlei" created="Sat, 15 Oct 2011 17:19:31 +0000"  >&lt;p&gt;The mapping is wrong as guilherme said, &lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;class Summary{
    /**
     * @OneToOne(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;Model\Lantern\Content\Article&quot;&lt;/span&gt;, inversedBy=&lt;span class=&quot;code-quote&quot;&gt;&quot;summary&quot;&lt;/span&gt;)
     * @JoinColumn(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;version_id&quot;&lt;/span&gt;, referencedColumnName=&lt;span class=&quot;code-quote&quot;&gt;&quot;version_id&quot;&lt;/span&gt;)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $version;    
...
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>