<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Sat May 18 23:24: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-1041/DC-1041.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-1041] Using -&gt;limit() in conjunction with many-to-many with mysql generates wrong SQL</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-1041</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Using -&amp;gt;limit() in conjunction with many-to-many relationships with mysql leads to strange SQL generated. The condition &lt;b&gt;id IS NULL&lt;/b&gt; is added in such case which is not correct at all.&lt;/p&gt;

&lt;p&gt;Here&apos;s example schema&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;User:
  columns:
    username: { type: string(255) }
  relations:
    Operators:
      foreignAlias: Users
      class:        Operator
      refClass:     OperatorUser

Operator:
  columns:
    username: { type: string(255) }
    type:     { type: integer }


OperatorUser:
  columns:
    user_id:      { type: integer }
    operator_id:  { type: integer }
  relations:
    Operator:
      foreignAlias: OperatorUser
    User:
      foreignAlias: OperatorUser
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And here&apos;s query which generates wrong 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;Doctrine_Core::getTable(&apos;User&apos;)
  -&amp;gt;createQuery(&apos;User&apos;)
  -&amp;gt;leftJoin(&apos;User.Operators Operator&apos;)
  -&amp;gt;addWhere(&apos;Operator.type = ?&apos;, 1)
  -&amp;gt;limit(10)
  -&amp;gt;offset(0)
  -&amp;gt;execute()
;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Expected SQL generated:&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-sql&quot;&gt;&lt;span class=&quot;code-keyword&quot;&gt;SELECT&lt;/span&gt; u.id AS u__id, u.username AS u__username, o.id AS o__id, o.username AS o__username, o.type AS o__type
&lt;span class=&quot;code-keyword&quot;&gt;FROM&lt;/span&gt; user u
LEFT JOIN operator_user o2  ON (u.id = o2.user_id)
LEFT JOIN operator o        ON o.id = o2.operator_id
&lt;span class=&quot;code-keyword&quot;&gt;WHERE&lt;/span&gt; (o.type = &apos;1&apos;)
LIMIT 10
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Actual SQL generated:&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-sql&quot;&gt;&lt;span class=&quot;code-keyword&quot;&gt;SELECT&lt;/span&gt; u.id AS u__id, u.username AS u__username, o.id AS o__id, o.username AS o__username, o.type AS o__type
&lt;span class=&quot;code-keyword&quot;&gt;FROM&lt;/span&gt; user u
LEFT JOIN operator_user o2  ON (u.id = o2.user_id)
LEFT JOIN operator o        ON o.id = o2.operator_id
&lt;span class=&quot;code-keyword&quot;&gt;WHERE&lt;/span&gt;
  u.id IS NULL # is not expected
  AND (o.type = &apos;1&apos;)
# there&apos;s no LIMIT clause
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Seems like here&apos;s code which causes the bug &lt;a href=&quot;https://github.com/doctrine/doctrine1/blob/master/lib/Doctrine/Query.php#L1307&quot; class=&quot;external-link&quot;&gt;https://github.com/doctrine/doctrine1/blob/master/lib/Doctrine/Query.php#L1307&lt;/a&gt;&lt;/p&gt;</description>
                <environment>mysql</environment>
            <key id="13229">DC-1041</key>
            <summary>Using -&gt;limit() in conjunction with many-to-many with mysql generates wrong SQL</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="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/open.png">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                                <assignee username="guilhermeblanco">Guilherme Blanco</assignee>
                                <reporter username="smileua">Evgeniy Afonichev</reporter>
                        <labels>
                    </labels>
                <created>Wed, 30 Nov 2011 09:26:19 +0000</created>
                <updated>Wed, 30 Nov 2011 09:51:21 +0000</updated>
                                                                    <component>Query</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>