<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Mon May 20 22:24:16 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-795/DDC-795.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-795] Wrong SQL statement when using loadOneToManyCollection</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-795</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;I have the following SQL&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;
CREATE TABLE `article` (
  `articleID` &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt;(11) NOT NULL AUTO_INCREMENT,
  `reference` varchar(255) DEFAULT NULL,
  `addDt` datetime DEFAULT NULL,
  PRIMARY KEY (`articleID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;


CREATE TABLE `articleRelated` (
  `articleID` &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt;(11) NOT NULL,
  `relatedArticleID` &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt;(11) NOT NULL,
  PRIMARY KEY (`articleID`,`relatedArticleID`),
  KEY `a1` (`articleID`),
  KEY `a2` (`relatedArticleID`),
  CONSTRAINT `a1` FOREIGN KEY (`articleID`) REFERENCES `article` (`articleID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `a2` FOREIGN KEY (`relatedArticleID`) REFERENCES `article` (`articleID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And these 2 models&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;&quot;&gt;&lt;b&gt;Article.php&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;&amp;lt;?php
/**
 * Model &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; article
 * 
 * @Table(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;article&quot;&lt;/span&gt;) 
 * @Entity
 */
class App_Model_Article
{

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; integer articleID
     * @Column(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;articleID&quot;&lt;/span&gt;, type=&lt;span class=&quot;code-quote&quot;&gt;&quot;integer&quot;&lt;/span&gt;, nullable=&lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) 
     * @GeneratedValue(strategy=&lt;span class=&quot;code-quote&quot;&gt;&quot;IDENTITY&quot;&lt;/span&gt;) 
     * @Id
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_articleID = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; string reference
     * @Column(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;reference&quot;&lt;/span&gt;, type=&lt;span class=&quot;code-quote&quot;&gt;&quot;string&quot;&lt;/span&gt;, nullable=&lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;, length=255)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_reference = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; datetime addDt
     * @Column(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;addDt&quot;&lt;/span&gt;, type=&lt;span class=&quot;code-quote&quot;&gt;&quot;datetime&quot;&lt;/span&gt;, nullable=&lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_addDt = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;

    /**
     * @OneToMany(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;App_Model_ArticleRelated&quot;&lt;/span&gt;, mappedBy=&lt;span class=&quot;code-quote&quot;&gt;&quot;_article&quot;&lt;/span&gt;, cascade={&lt;span class=&quot;code-quote&quot;&gt;&quot;persist&quot;&lt;/span&gt;})
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_articleRelatedRefArticle = array();

    /**
     * @OneToMany(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;App_Model_ArticleRelated&quot;&lt;/span&gt;, mappedBy=&lt;span class=&quot;code-quote&quot;&gt;&quot;_relatedArticle&quot;&lt;/span&gt;, cascade={&lt;span class=&quot;code-quote&quot;&gt;&quot;persist&quot;&lt;/span&gt;})
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_articleRelatedRefRelatedArticle = array();
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;and &lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;&quot;&gt;&lt;b&gt;ArticleRelated.php&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;&amp;lt;?php

/**
 * Model &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; articleRelated
 * 
 * @Table(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;articleRelated&quot;&lt;/span&gt;) 
 * @Entity
 */
class App_Model_ArticleRelated
{

    /**
     * @ManyToOne(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;App_Model_Article&quot;&lt;/span&gt;) 
     * @JoinColumn(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;articleID&quot;&lt;/span&gt;, referencedColumnName=&lt;span class=&quot;code-quote&quot;&gt;&quot;articleID&quot;&lt;/span&gt;) 
     * @Id
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_article = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;

    /**
     * @ManyToOne(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;App_Model_Article&quot;&lt;/span&gt;) 
     * @JoinColumn(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;relatedArticleID&quot;&lt;/span&gt;, referencedColumnName=&lt;span class=&quot;code-quote&quot;&gt;&quot;articleID&quot;&lt;/span&gt;) 
     * @Id
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_relatedArticle = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When I do 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;$firstArticle = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_entityManager-&amp;gt;find(&apos;App_Model_Article&apos;, 54);
      
$related = $firstArticle-&amp;gt;getArticleRelated(&apos;article&apos;);
foreach ($related as $art) {
       	var_dump($art);
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;it generates the following SQL&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 , t1.articleID AS articleID0, t1.relatedArticleID AS relatedArticleID2 FROM articleRelated t1 WHERE articleID = ?
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I tracked the problem down to the following method&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;&quot;&gt;&lt;b&gt;Doctrine/ORM/Persisters/BasicEntityPersister.php&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;&lt;span class=&quot;code-comment&quot;&gt;//...
&lt;/span&gt;&lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function _getSelectColumnListSQL()
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_selectColumnListSql !== &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_selectColumnListSql;
        }

        $columnList = &apos;&apos;;

        &lt;span class=&quot;code-comment&quot;&gt;// Add regular columns to select list
&lt;/span&gt;        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_class-&amp;gt;fieldNames as $field) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($columnList) $columnList .= &apos;, &apos;;
            $columnList .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_getSelectColumnSQL($field, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_class);
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_selectColumnListSql = $columnList . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_getSelectJoinColumnsSQL($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_class);
		
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_selectColumnListSql;
    }
&lt;span class=&quot;code-comment&quot;&gt;//....&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Because $this-&amp;gt;_class-&amp;gt;fieldNames is empty for my class, $columnList will also be empty. &lt;br/&gt;
$this-&amp;gt;_getSelectJoinColumnsSQL($this-&amp;gt;_class) generates &lt;br/&gt;
&quot;, t1.articleID AS articleID0, t1.relatedArticleID AS relatedArticleID2&quot;&lt;br/&gt;
so $this-&amp;gt;_selectColumnListSql == &quot;, t1.articleID AS articleID0, t1.relatedArticleID AS relatedArticleID2&quot;&lt;/p&gt;

&lt;p&gt;I fixed the problem by adding trim:&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;$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_selectColumnListSql = trim($columnList . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_getSelectJoinColumnsSQL($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_class), &apos;,&apos;);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
            <key id="11898">DDC-795</key>
            <summary>Wrong SQL statement when using loadOneToManyCollection</summary>
                <type id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/subtask_alternate.png">Sub-task</type>
                    <parent id="10344">DDC-117</parent>
                        <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="1">Fixed</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="tbo">Van Hauwaert Bert</reporter>
                        <labels>
                    </labels>
                <created>Thu, 9 Sep 2010 06:07:26 +0000</created>
                <updated>Tue, 28 Dec 2010 13:06:22 +0000</updated>
                    <resolved>Tue, 28 Dec 2010 13:06:22 +0000</resolved>
                            <version>2.0-BETA4</version>
                                <fixVersion>2.1</fixVersion>
                                <component>ORM</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="14315" author="beberlei" created="Fri, 10 Sep 2010 02:49:31 +0000"  >&lt;p&gt;Foreign Keys as Primary Keys are currently not supported (except for the &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-117&quot; title=&quot;Allow @Id on @ManyToOne fields&quot;&gt;&lt;del&gt;DDC-117&lt;/del&gt;&lt;/a&gt; experimental branch, scheduled for 2.1)&lt;/p&gt;

&lt;p&gt;See: &lt;a href=&quot;http://www.doctrine-project.org/projects/orm/2.0/docs/reference/limitations-and-known-issues/en#current-limitations:foreign-keys-as-identifiers&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/projects/orm/2.0/docs/reference/limitations-and-known-issues/en#current-limitations:foreign-keys-as-identifiers&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="14320" author="tbo" created="Fri, 10 Sep 2010 12:19:43 +0000"  >&lt;p&gt;Sorry Benjamin, I should have mentioned that I work with that branch. &lt;/p&gt;</comment>
                    <comment id="14346" author="beberlei" created="Sun, 12 Sep 2010 03:41:04 +0000"  >&lt;p&gt;Ah ok, i&apos;ll move and downgrade priority because there is so much to do on the master branch before release.&lt;/p&gt;</comment>
                    <comment id="15047" author="beberlei" created="Tue, 28 Dec 2010 13:06:22 +0000"  >&lt;p&gt;Fixed in &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-117&quot; title=&quot;Allow @Id on @ManyToOne fields&quot;&gt;&lt;del&gt;DDC-117&lt;/del&gt;&lt;/a&gt; branch.&lt;/p&gt;</comment>
                </comments>
                <issuelinks>
                        <issuelinktype id="10000">
                <name>Duplicate</name>
                                <outwardlinks description="duplicates">
                            <issuelink>
            <issuekey id="10344">DDC-117</issuekey>
        </issuelink>
                    </outwardlinks>
                                            </issuelinktype>
                    </issuelinks>
                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>