<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Thu May 23 00:20:19 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/DC-290/DC-290.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>[DC-290] Relations need alias</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-290</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;While implementing a Record_Template and manipulating a query by using the preDqlSelect Event, i got massive problems if the query was generated by a refresh() or refreshRelated() call. I found out that the issue appears because the query has no alias for the table then. This makes it hard to add forther (sub-)selects to the query via preDqlSelect, e.g.&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;$params = $event-&amp;gt;getParams();
		$alias = $params[&apos;alias&apos;];

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;(!$query-&amp;gt;isSubquery() &amp;amp;&amp;amp; $alias == $queryClone-&amp;gt;getRootAlias()) {	
				
				
				$countQuery = &apos;(SELECT COUNT(&apos;.$alias.&apos;_tcount.uid) FROM &apos;.$modelName.&apos; &apos;.$alias.&apos;_tcount WHERE &apos;.$alias.&apos;.&apos;.$groupId.&apos;=&apos;.$alias.&apos;_tcount.&apos;.$groupId.&apos;) AS &apos;.$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_options[&apos;terminationCount&apos;];
				
				$query-&amp;gt;addSelect($countQuery);
			}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;



&lt;p&gt;The issue is solved by adding an alias in the foreignKey and localKey relation types&apos; fetchRelatedFor methods (at least that&apos;s sufficient for my issue, maybe there is a need to add similar lines to the other relation types).&lt;/p&gt;



&lt;p&gt;Doctrine_Relation_ForeignKey (from line 60):&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;$alias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getTable()-&amp;gt;getComponentName().&apos;_rel&apos;;
            	
                $dql  = &apos;FROM &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getTable()-&amp;gt;getComponentName()
                      .&apos; &apos;.$alias. &apos; WHERE &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getCondition($alias) . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getOrderBy(&lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;



&lt;p&gt;Doctrine_Relation_LocalKey (from line 58):&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;$alias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getTable()-&amp;gt;getComponentName().&apos;_rel&apos;;
        	
            $dql  = &apos;FROM &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getTable()-&amp;gt;getComponentName()
                 .&apos; &apos;.$alias. &apos; WHERE &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getCondition($alias) . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getOrderBy(&lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
            <key id="10506">DC-290</key>
            <summary>Relations need alias</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="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/reopened.png">Reopened</status>
                    <resolution id="-1">Unresolved</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="jensen83">Christian Jaentsch</reporter>
                        <labels>
                    </labels>
                <created>Wed, 25 Nov 2009 13:24:48 +0000</created>
                <updated>Wed, 9 Jun 2010 16:08:24 +0000</updated>
                                    <version>1.2.0-RC1</version>
                                                <component>Relations</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="10921" author="jwage" created="Mon, 30 Nov 2009 17:45:00 +0000"  >&lt;p&gt;If no alias is explicitly defined, the alias is automatically set to the model name. So in your code change you changed it from &quot;ModelName&quot; to &quot;ModelName_rel&quot;. If you had the following:&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 User
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The alias would be &quot;User&quot; and it is the same as if you did:&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 User User
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="10938" author="jensen83" created="Tue, 1 Dec 2009 10:37:50 +0000"  >&lt;p&gt;unfortunately this does not solve my problem... i narrowed it down to be a problem with addPendingJoinCondition in such a case.&lt;/p&gt;

&lt;p&gt;here is a short scenario of what i want to do...&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;$modelName = &apos;Exhibition&apos;;
$alias = &lt;span class=&quot;code-quote&quot;&gt;&quot;exhibitionalias&quot;&lt;/span&gt;;
$subAlias = &apos;exhibitionsub&apos;;
		
$query = Doctrine_Query::create()
-&amp;gt;from($modelName.&apos; &apos;.$alias);
		
$subQuery .= &apos;SELECT &apos;.$subAlias.&apos;.id FROM &apos;.$modelName.&apos; &apos;.$subAlias.&apos; WHERE &apos;.$subAlias.&apos;.id = &apos;.$alias.&apos;.id&apos;;
$query-&amp;gt;addPendingJoinCondition($alias, $alias.&apos;.id IN (&apos;.$subQuery.&apos;)&apos;);
		
$query-&amp;gt;execute();
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;this works so far as the alias is different from the model name... but if i change&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;$alias = &lt;span class=&quot;code-quote&quot;&gt;&quot;Exhibition&quot;&lt;/span&gt;;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;i get the exception&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;exception &apos;Doctrine_Exception&apos; with message &apos;Couldn&apos;t find class exhibitionsub&apos; in /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Table.php:299
Stack trace:
#0 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Table.php(249): Doctrine_Table-&amp;gt;initDefinition()
#1 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Connection.php(1126): Doctrine_Table-&amp;gt;__construct(&apos;exhibitionsub&apos;, &lt;span class=&quot;code-object&quot;&gt;Object&lt;/span&gt;(Doctrine_Connection_Mysql), &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
#2 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1924): Doctrine_Connection-&amp;gt;getTable(&apos;exhibitionsub&apos;)
#3 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1722): Doctrine_Query-&amp;gt;loadRoot(&apos;exhibitionsub&apos;, &apos;exhibitionsub&apos;)
#4 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Where.php(76): Doctrine_Query-&amp;gt;load(&apos;exhibitionsub&apos;, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;)
#5 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Condition.php(92): Doctrine_Query_Where-&amp;gt;load(&apos;exhibitionsub.i...&apos;)
#6 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(2077): Doctrine_Query_Condition-&amp;gt;parse(&apos;exhibitionsub.i...&apos;)
#7 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1156): Doctrine_Query_Abstract-&amp;gt;_processDqlQueryPart(&apos;where&apos;, Array)
#8 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1122): Doctrine_Query-&amp;gt;buildSqlQuery(&lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;)
#9 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1137): Doctrine_Query-&amp;gt;getSqlQuery(Array, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;)
#10 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1106): Doctrine_Query_Abstract-&amp;gt;_getDqlCallbackComponents(Array)
#11 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1143): Doctrine_Query_Abstract-&amp;gt;_preQuery()
#12 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1122): Doctrine_Query-&amp;gt;buildSqlQuery(&lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
#13 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/JoinCondition.php(87): Doctrine_Query-&amp;gt;getSqlQuery()
#14 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Condition.php(92): Doctrine_Query_JoinCondition-&amp;gt;load(&apos;Exhibition.id I...&apos;)
#15 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1089): Doctrine_Query_Condition-&amp;gt;parse(&apos;Exhibition.id I...&apos;)
#16 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1013): Doctrine_Query-&amp;gt;_processPendingJoinConditions(&apos;Exhibition&apos;)
#17 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1228): Doctrine_Query-&amp;gt;_buildSqlFromPart()
#18 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1122): Doctrine_Query-&amp;gt;buildSqlQuery(&lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;)
#19 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1137): Doctrine_Query-&amp;gt;getSqlQuery(Array, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;)
#20 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1106): Doctrine_Query_Abstract-&amp;gt;_getDqlCallbackComponents(Array)
#21 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1001): Doctrine_Query_Abstract-&amp;gt;_preQuery(Array)
#22 /&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt;/www/erh_eeecore/app/modules/&lt;span class=&quot;code-keyword&quot;&gt;default&lt;/span&gt;/controllers/ExhibitionsController.php(75): Doctrine_Query_Abstract-&amp;gt;execute()
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="11057" author="jwage" created="Mon, 7 Dec 2009 19:50:11 +0000"  >&lt;p&gt;Hmm. Christian, your issue doesn&apos;t seem at all related to the original issue. It seems like an entirely different problem, no?&lt;/p&gt;</comment>
                    <comment id="11081" author="jensen83" created="Tue, 8 Dec 2009 13:38:21 +0000"  >&lt;p&gt;Well, I don&apos;t know where the reason for the problem is exactly... I just solved my problem by adding an alias to the foreignKey and localKey relations. The actual problem seems to be located in how the query is processed if the alias is equal to the name of the &quot;from&quot;-model. this causes problems while adding pending join conditions.&lt;/p&gt;</comment>
                    <comment id="11098" author="jwage" created="Tue, 8 Dec 2009 18:04:42 +0000"  >&lt;p&gt;Ok, well what you described is totally un-related to this issue. If you have found a bug you can open another ticket with detailed information and a failing test case. Thanks, Jon&lt;/p&gt;</comment>
                    <comment id="13197" author="jwage" created="Tue, 8 Jun 2010 15:07:07 +0000"  >&lt;p&gt;Can you show a patch with your changes?&lt;/p&gt;</comment>
                    <comment id="13260" author="jensen83" created="Wed, 9 Jun 2010 16:08:24 +0000"  >&lt;p&gt;My patch is as shown in the description of this issue:&lt;/p&gt;

&lt;p&gt;Doctrine_Relation_ForeignKey (from line 60):&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;$alias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getTable()-&amp;gt;getComponentName().&apos;_rel&apos;;
            	
                $dql  = &apos;FROM &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getTable()-&amp;gt;getComponentName()
                      .&apos; &apos;.$alias. &apos; WHERE &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getCondition($alias) . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getOrderBy(&lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;



&lt;p&gt;Doctrine_Relation_LocalKey (from line 58):&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;$alias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getTable()-&amp;gt;getComponentName().&apos;_rel&apos;;
        	
            $dql  = &apos;FROM &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getTable()-&amp;gt;getComponentName()
                 .&apos; &apos;.$alias. &apos; WHERE &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getCondition($alias) . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getOrderBy(&lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>