<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Wed May 22 00:42:53 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-2131/DDC-2131.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-2131] Fetch join not working on class table inheritance</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-2131</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;I have an entity Appointment, that is associated with application forms.&lt;br/&gt;
I have an abstract class AbstractApplicationForm that has multiple (6) child classes.&lt;/p&gt;

&lt;p&gt;The mapping info for the abstract application form looks like this:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-style: solid;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;border-bottom-style: solid;&quot;&gt;&lt;b&gt;AbstractApplicationForm.php&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
/**
 * @ORM\Entity()
 * @ORM\Table(&lt;span class=&quot;code-quote&quot;&gt;&quot;applicationform&quot;&lt;/span&gt;)
 * @ORM\InheritanceType(&lt;span class=&quot;code-quote&quot;&gt;&quot;JOINED&quot;&lt;/span&gt;)
 * @ORM\DiscriminatorColumn(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;discr&quot;&lt;/span&gt;, type=&lt;span class=&quot;code-quote&quot;&gt;&quot;string&quot;&lt;/span&gt;)
 * @ORM\DiscriminatorMap({
 *     &lt;span class=&quot;code-quote&quot;&gt;&quot;slc&quot;&lt;/span&gt; = &lt;span class=&quot;code-quote&quot;&gt;&quot;SlcApplicationForm&quot;&lt;/span&gt;,
 *     &lt;span class=&quot;code-quote&quot;&gt;&quot;vsdb&quot;&lt;/span&gt; = &lt;span class=&quot;code-quote&quot;&gt;&quot;VsdbApplicationForm&quot;&lt;/span&gt;,
 *     &lt;span class=&quot;code-quote&quot;&gt;&quot;vss&quot;&lt;/span&gt; = &lt;span class=&quot;code-quote&quot;&gt;&quot;VssApplicationForm&quot;&lt;/span&gt;,
 *     &lt;span class=&quot;code-quote&quot;&gt;&quot;opzd&quot;&lt;/span&gt; = &lt;span class=&quot;code-quote&quot;&gt;&quot;OpzdApplicationForm&quot;&lt;/span&gt;,
 *     &lt;span class=&quot;code-quote&quot;&gt;&quot;vzu&quot;&lt;/span&gt; = &lt;span class=&quot;code-quote&quot;&gt;&quot;VzuApplicationForm&quot;&lt;/span&gt;,
 *     &lt;span class=&quot;code-quote&quot;&gt;&quot;opzdvzu&quot;&lt;/span&gt; = &lt;span class=&quot;code-quote&quot;&gt;&quot;OpzdVzuApplicationForm&quot;&lt;/span&gt;
 * })
 */
&lt;span class=&quot;code-keyword&quot;&gt;abstract&lt;/span&gt; class AbstractApplicationForm
...
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I have an OneToMany connection from Appointment to AbstractApplicationForm.&lt;br/&gt;
When i construct an DQL, to get an appointment with only specific application forms it gets wrong translated into SQL.&lt;/p&gt;

&lt;p&gt;For instance if the query builder looks like this:&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;
$qb-&amp;gt;select(&apos;ap, af&apos;)
   -&amp;gt;from(Appointment::getClass(), &apos;ap&apos;)
   -&amp;gt;leftJoin(&apos;ap.applicationForms&apos;, &apos;af&apos;, &apos;WITH&apos;, &apos;af.id = 123456789&apos;)
   -&amp;gt;andWhere(&apos;ap.id = :appointment&apos;)
   -&amp;gt;setParameter(&apos;appointment&apos;, $appointment);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So with this dql i should get an appointment with filtered application forms. In this case it whould return an appointment with only one application form (that with the id 123456789).&lt;br/&gt;
But it returns all associated application form instead on only that with the id 123456789, because it ignores the with clause.&lt;/p&gt;

&lt;p&gt;Here is the SQL that gets generated from the DQL:&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;
SELECT ...
FROM program_execution_activity_appointment p8_, program_execution_activity_appointment p0_
LEFT JOIN applicationform a1_ ON p0_.id = a1_.appointment_id 
LEFT JOIN applicationform_slc a2_ ON a1_.id = a2_.id 
LEFT JOIN applicationform_vsdb a3_ ON a1_.id = a3_.id 
LEFT JOIN applicationform_vss a4_ ON a1_.id = a4_.id 
LEFT JOIN applicationform_opzd a5_ ON a1_.id = a5_.id 
LEFT JOIN applicationform_vzu a6_ ON a1_.id = a6_.id 
LEFT JOIN applicationform_opzdvzu a7_ ON a1_.id = a7_.id AND (a1_.id = 123456789) 
WHERE p0_.id = 1
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The problem i see here is that the AND is added to the last join (applicationform_opzdvzu). But it should added to the first join (applicationform). Because the first join represents the parent entity (AbstractApplicationForm).&lt;br/&gt;
There is also a problem in the FROM clause. The problem is that &lt;b&gt;program_execution_activity_appointment p8_&lt;/b&gt; is never used anywhere else, except in the from clause.&lt;/p&gt;

&lt;p&gt;The generated query should look like this:&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;
SELECT ...
FROM program_execution_activity_appointment p0_
LEFT JOIN applicationform a1_ ON p0_.id = a1_.appointment_id AND (a1_.id = 123456789) 
LEFT JOIN applicationform_slc a2_ ON a1_.id = a2_.id
LEFT JOIN applicationform_vsdb a3_ ON a1_.id = a3_.id
LEFT JOIN applicationform_vss a4_ ON a1_.id = a4_.id
LEFT JOIN applicationform_opzd a5_ ON a1_.id = a5_.id
LEFT JOIN applicationform_vzu a6_ ON a1_.id = a6_.id
LEFT JOIN applicationform_opzdvzu a7_ ON a1_.id = a7_.id
WHERE p0_.id = 1
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This sql works as expected.&lt;/p&gt;

&lt;p&gt;I hope i was clear enough what the problem is.&lt;/p&gt;</description>
                <environment></environment>
            <key id="14202">DDC-2131</key>
            <summary>Fetch join not working on class table inheritance</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="3">Duplicate</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="alsar">alsar</reporter>
                        <labels>
                    </labels>
                <created>Wed, 7 Nov 2012 08:44:53 +0000</created>
                <updated>Mon, 12 Nov 2012 14:27:21 +0000</updated>
                    <resolved>Mon, 12 Nov 2012 14:25:43 +0000</resolved>
                            <version>2.3</version>
                                                <component>ORM</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>2</watches>
                        <comments>
                    <comment id="18969" author="beberlei" created="Mon, 12 Nov 2012 14:25:43 +0000"  >&lt;p&gt;This is a duplicate of &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-1256&quot; title=&quot;Generated SQL error with DQL WITH and JOINED inheritance&quot;&gt;&lt;del&gt;DDC-1256&lt;/del&gt;&lt;/a&gt;	&lt;/p&gt;</comment>
                    <comment id="18970" author="beberlei" created="Mon, 12 Nov 2012 14:27:21 +0000"  >&lt;p&gt;This is not easy to fix as you can see &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-1256&quot; title=&quot;Generated SQL error with DQL WITH and JOINED inheritance&quot;&gt;&lt;del&gt;DDC-1256&lt;/del&gt;&lt;/a&gt;	is open for a while. However in your case there is an easy solution, why not fetch the appointment form by id, and then go the association to the appointment? This is the inverse operation on that relation, but suits your needs perfectly.&lt;/p&gt;</comment>
                </comments>
                <issuelinks>
                        <issuelinktype id="10000">
                <name>Duplicate</name>
                                <outwardlinks description="duplicates">
                            <issuelink>
            <issuekey id="12797">DDC-1256</issuekey>
        </issuelink>
                    </outwardlinks>
                                            </issuelinktype>
                    </issuelinks>
                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>