<!--
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Thu May 23 04:20:15 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/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+%3D+DC+AND+resolution+%3D+Unresolved+AND+component+%3D+Pager+ORDER+BY+priority+DESC&tempMax=1000&field=key&field=summary
-->
<!-- If you wish to do custom client-side styling of RSS, uncomment this:
<?xml-stylesheet href="http://www.doctrine-project.org/jira/styles/jiraxml2html.xsl" type="text/xsl"?>
-->
<rss version="0.92">
    <channel>
        <title>Doctrine Project</title>
        <link>http://www.doctrine-project.org/jira/secure/IssueNavigator.jspa?reset=true&amp;jqlQuery=project+%3D+DC+AND+resolution+%3D+Unresolved+AND+component+%3D+Pager+ORDER+BY+priority+DESC</link>
        <description>An XML representation of a search request</description>
                <language>en-us</language>
                        <issue start="0" end="6" total="6"/>
                <build-info>
            <version>5.2.7</version>
            <build-number>850</build-number>
            <build-date>21-02-2013</build-date>
        </build-info>
<item>
            <title>[DC-914] Doctrine_Pager ignores custom COUNT query</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-914</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>
&lt;p&gt;I found some problem when I tried to define custom query for results counting. Defined custom COUNT query is totally ignored and executed default one. I will give you full description of problem bellow.&lt;/p&gt;

&lt;p&gt;We have following source code:&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; 
$q_select = Doctrine_Query::create ()
-&amp;gt;select ( &apos;DISTINCT p.product_name AS product_name&apos; )
-&amp;gt;from ( &apos;Product p&apos; )
-&amp;gt;where( &apos;p.product_name LIKE ?&apos;, &apos;%motorola%&apos;);
				
$q_count = Doctrine_Query::create ()
-&amp;gt;select ( &apos;COUNT (DISTINCT p.product_name) num_results&apos; )
-&amp;gt;from ( &apos;Product p&apos; )
-&amp;gt;where( &apos;p.product_name LIKE ?&apos;, &apos;%motorola%&apos;);
												
$pager = new Doctrine_Pager( $q_select, 1, 25 );										
$pager-&amp;gt;setCountQuery($q_count);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;Let&apos;s check custom query before calling $pager-&amp;gt;execute() method:&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; 
echo $pager-&amp;gt;getCountQuery(); 
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;Output:&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; 
SELECT COUNT (DISTINCT p.product_name) num_results FROM Product p WHERE p.product_name LIKE ?
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;Looks like until now is everything is correct.  Let&apos;s call $pager-&amp;gt;execute() method:&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; 
$products = $pager-&amp;gt;execute(); 
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;Let&apos;s check executed queries using Symfony SQL queries log panel:&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;SELECT COUNT(*) AS num_results FROM product p WHERE p.product_name LIKE &apos;%motorola%&apos;
7.27s, &quot;doctrine&quot; connection

SELECT DISTINCT p.product_name AS p__0 FROM product p WHERE (p.product_name LIKE &apos;%motorola%&apos;) LIMIT 25
3.25s, &quot;doctrine&quot; connection
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;Executed COUNT query is not same we set using $pager-&amp;gt;setCountQuery($q_count). Our defined custom COUNT query is totally ignored and executed default one:&lt;/p&gt;

&lt;p&gt;INSTEAD OF THIS  CUSTOM COUNT  QUERY:&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;SELECT COUNT (DISTINCT p.product_name) num_results FROM Product p WHERE p.product_name LIKE &apos;%motorola%&apos;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;EXECUTED DEFAULT COUNT QUERY:&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;SELECT COUNT(*) AS num_results FROM product p WHERE p.product_name LIKE &apos;%motorola%&apos;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; </description>
                <environment>Zend Server CE</environment>
            <key id="12058">DC-914</key>
            <summary>Doctrine_Pager ignores custom COUNT query</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="arnlukas">Arnoldas Lukasevicius</reporter>
                        <labels>
                    </labels>
                <created>Tue, 2 Nov 2010 06:23:30 +0000</created>
                <updated>Mon, 7 Nov 2011 22:54:46 +0000</updated>
                                    <version>1.2.3</version>
                                                <component>Pager</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="16774" author="blueskypoa" created="Mon, 7 Nov 2011 22:54:46 +0000"  >&lt;p&gt;I found a possible solution to the problem.&lt;/p&gt;

&lt;p&gt;That occurs not because the Pager countQuery but in a method used inside the Query class.&lt;/p&gt;

&lt;p&gt;When you set the Query or CountQuery for Pager and execute it, it calls a Query method called count(). This method by yourself call another Query class method named Query::getCountSqlQuery().&lt;/p&gt;

&lt;p&gt;This method rather than simply execute the query that you passed earlier, simply create a new query.&lt;/p&gt;

&lt;p&gt;Below is a possible solution to the problem:&lt;/p&gt;

&lt;p&gt;Query.php (Doctrine Stable 1.2.4)&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;
--- Query.php	2011-11-07 20:52:48.000000000 -0200
+++ Query.php	2011-11-07 20:51:58.000000000 -0200
@@ -2049,40 +2049,7 @@
         &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents) == 1 &amp;amp;&amp;amp; empty($having)) {
             $q .= $from . $where . $groupby . $having;
         } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
-
-            &lt;span class=&quot;code-comment&quot;&gt;// Subselect fields will contain only the pk of root entity
&lt;/span&gt;-            $ta = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias);
-
-            $map = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootDeclaration();
-            $idColumnNames = $map[&apos;table&apos;]-&amp;gt;getIdentifierColumnNames();
-
-            $pkFields = $ta . &apos;.&apos; . implode(&apos;, &apos; . $ta . &apos;.&apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteMultipleIdentifier($idColumnNames));
-
-            &lt;span class=&quot;code-comment&quot;&gt;// We need to &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; some magic in select fields &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; the query contain anything in having clause
&lt;/span&gt;-            $selectFields = $pkFields;
-
-            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($having)) {
-                &lt;span class=&quot;code-comment&quot;&gt;// For each field defined in select clause
&lt;/span&gt;-                foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;select&apos;] as $field) {
-                    &lt;span class=&quot;code-comment&quot;&gt;// We only include aggregate expressions to count query
&lt;/span&gt;-                    &lt;span class=&quot;code-comment&quot;&gt;// This is needed because HAVING clause will use field aliases
&lt;/span&gt;-                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($field, &apos;(&apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
-                        $selectFields .= &apos;, &apos; . $field;
-                    }
-                }
-                &lt;span class=&quot;code-comment&quot;&gt;// Add having fields that got stripped out of select
&lt;/span&gt;-                preg_match_all(&apos;/`[a-z0-9_]+`\.`[a-z0-9_]+`/i&apos;, $having, $matches, PREG_PATTERN_ORDER);
-                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($matches[0]) &amp;gt; 0) {
-                    $selectFields .= &apos;, &apos; . implode(&apos;, &apos;, array_unique($matches[0]));
-                }
-            }
-
-            &lt;span class=&quot;code-comment&quot;&gt;// If we &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; not have a custom group by, apply the &lt;span class=&quot;code-keyword&quot;&gt;default&lt;/span&gt; one
&lt;/span&gt;-            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (empty($groupby)) {
-                $groupby = &apos; GROUP BY &apos; . $pkFields;
-            }
-
-            $q .= &apos;(SELECT &apos; . $selectFields . &apos; FROM &apos; . $from . $where . $groupby . $having . &apos;) &apos;
+            $q .= &apos;( &apos;.$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlQuery().&apos; ) &apos;
                 . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier(&apos;dctrn_count_query&apos;);
         }
         &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $q;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-897] Pager ignores default model hasMany ORDER BY statements, caused by getLimitSubquery ignoring same</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-897</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Our model configuration includes several hasMany statements, for example:&lt;/p&gt;

&lt;p&gt;        $this-&amp;gt;hasMany(&apos;Subcategory as Subcategories&apos;, array(&lt;br/&gt;
            &apos;refClass&apos; =&amp;gt; &apos;SubcategoryTone&apos;,&lt;br/&gt;
            &apos;local&apos; =&amp;gt; &apos;tone_id&apos;,&lt;br/&gt;
            &apos;foreign&apos; =&amp;gt; &apos;subcategory_id&apos;,&lt;br/&gt;
            &apos;cascade&apos; =&amp;gt; array(&apos;delete&apos;),&lt;br/&gt;
            &apos;orderBy&apos; =&amp;gt; &apos;order_id&apos;,&lt;br/&gt;
        ));&lt;/p&gt;

&lt;p&gt;We noticed that the ORDER BY directive worked just fine with a normal query, but the order by was being ignored when we fed it into the Pager.&lt;/p&gt;

&lt;p&gt;For example:&lt;br/&gt;
            $aa = $t-&amp;gt;execute(array(), Doctrine_Core::HYDRATE_ARRAY);&lt;br/&gt;
            var_dump($aa&lt;span class=&quot;error&quot;&gt;&amp;#91;4&amp;#93;&lt;/span&gt;);&lt;/p&gt;

&lt;p&gt;            $pager = new Doctrine_Pager($t, $currentPage, $resultsPerPage);&lt;br/&gt;
            $bb = $pager-&amp;gt;execute(array(), Doctrine_Core::HYDRATE_ARRAY);&lt;/p&gt;

&lt;p&gt;            var_dump($bb&lt;span class=&quot;error&quot;&gt;&amp;#91;4&amp;#93;&lt;/span&gt;);&lt;/p&gt;

&lt;p&gt;These two var_dumps would give different results because the ORDER BY is ignored by the limit subquery in the pager.&lt;/p&gt;</description>
                <environment></environment>
            <key id="12025">DC-897</key>
            <summary>Pager ignores default model hasMany ORDER BY statements, caused by getLimitSubquery ignoring same</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="angrygreenfrogs">Andrew Eross</reporter>
                        <labels>
                    </labels>
                <created>Fri, 22 Oct 2010 02:50:21 +0000</created>
                <updated>Wed, 10 Nov 2010 01:41:21 +0000</updated>
                                    <version>1.2.3</version>
                                                <component>Pager</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="14593" author="angrygreenfrogs" created="Fri, 22 Oct 2010 03:05:23 +0000"  >&lt;p&gt;I&apos;ve also found a fix for the issue (thanks to George over here for finding the location of the problem) ... we found that simply moving the ORDER BY generation code inside of buildSqlQuery() to be ABOVE the if block containing getLimitSubquery() resolves the issue.&lt;/p&gt;

&lt;p&gt;We&apos;re not super familiar with the Doctrine code-base, so everything looks to work fine after moving the code block, and it fixes the issue, but would love to hear if this is a real fix.&lt;/p&gt;

&lt;p&gt;diff from 1.2.3 via our SVN:&lt;/p&gt;

&lt;p&gt;Index: Query.php&lt;br/&gt;
===================================================================&lt;br/&gt;
&amp;#8212; Query.php   (revision 1120)&lt;br/&gt;
+++ Query.php   (working copy)&lt;br/&gt;
@@ -1256,7 +1256,46 @@&lt;br/&gt;
                 $this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;where&amp;#39;&amp;#93;&lt;/span&gt;[] = &apos;(&apos; . $string . &apos;)&apos;;&lt;br/&gt;
             }&lt;br/&gt;
         }&lt;br/&gt;
+        &lt;br/&gt;
+    // Fix the orderbys so we only have one orderby per value&lt;br/&gt;
+        foreach ($this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;orderby&amp;#39;&amp;#93;&lt;/span&gt; as $k =&amp;gt; $orderBy) {&lt;br/&gt;
+            $e = explode(&apos;, &apos;, $orderBy);&lt;br/&gt;
+            unset($this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;orderby&amp;#39;&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;$k&amp;#93;&lt;/span&gt;);&lt;br/&gt;
+            foreach ($e as $v) &lt;/p&gt;
{
+                $this-&amp;gt;_sqlParts[&apos;orderby&apos;][] = $v;
+            }
&lt;p&gt;+        }&lt;/p&gt;

&lt;p&gt;+        // Add the default orderBy statements defined in the relationships and table classes&lt;br/&gt;
+        // Only do this for SELECT queries&lt;br/&gt;
+        if ($this-&amp;gt;_type === self::SELECT) {&lt;br/&gt;
+            foreach ($this-&amp;gt;_queryComponents as $alias =&amp;gt; $map) {&lt;br/&gt;
+                $sqlAlias = $this-&amp;gt;getSqlTableAlias($alias);&lt;br/&gt;
+                if (isset($map&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;relation&amp;#39;&amp;#93;&lt;/span&gt;)) {&lt;br/&gt;
+                    $orderBy = $map&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;relation&amp;#39;&amp;#93;&lt;/span&gt;-&amp;gt;getOrderByStatement($sqlAlias, true);&lt;br/&gt;
+                    if ($orderBy == $map&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;relation&amp;#39;&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;orderBy&amp;#39;&amp;#93;&lt;/span&gt;) {&lt;br/&gt;
+                        if (isset($map&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;ref&amp;#39;&amp;#93;&lt;/span&gt;)) &lt;/p&gt;
{
+                            $orderBy = $map[&apos;relation&apos;][&apos;refTable&apos;]-&amp;gt;processOrderBy($sqlAlias, $map[&apos;relation&apos;][&apos;orderBy&apos;], true);
+                        }
&lt;p&gt; else &lt;/p&gt;
{
+                            $orderBy = null;
+                        }
&lt;p&gt;+                    }&lt;br/&gt;
+                } else &lt;/p&gt;
{
+                    $orderBy = $map[&apos;table&apos;]-&amp;gt;getOrderByStatement($sqlAlias, true);
+                }
&lt;p&gt;+&lt;br/&gt;
+                if ($orderBy) {&lt;br/&gt;
+                    $e = explode(&apos;,&apos;, $orderBy);&lt;br/&gt;
+                    $e = array_map(&apos;trim&apos;, $e);&lt;br/&gt;
+                    foreach ($e as $v) {&lt;br/&gt;
+                        if ( ! in_array($v, $this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;orderby&amp;#39;&amp;#93;&lt;/span&gt;)) &lt;/p&gt;
{
+                            $this-&amp;gt;_sqlParts[&apos;orderby&apos;][] = $v;
+                        }
&lt;p&gt;+                    }&lt;br/&gt;
+                }&lt;br/&gt;
+            }&lt;br/&gt;
+        }&lt;br/&gt;
+&lt;br/&gt;
         $modifyLimit = true;&lt;br/&gt;
         $limitSubquerySql = &apos;&apos;;&lt;/p&gt;

&lt;p&gt;@@ -1307,47 +1346,8 @@&lt;/p&gt;

&lt;p&gt;             $q .= &apos; WHERE &apos; . $limitSubquerySql . $where;&lt;br/&gt;
             //   .  (($limitSubquerySql == &apos;&apos; &amp;amp;&amp;amp; count($this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;where&amp;#39;&amp;#93;&lt;/span&gt;) == 1) ? substr($where, 1, -1) : $where);&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;}&lt;br/&gt;
+        }        &lt;/li&gt;
&lt;/ul&gt;


&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;// Fix the orderbys so we only have one orderby per value&lt;/li&gt;
	&lt;li&gt;foreach ($this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;orderby&amp;#39;&amp;#93;&lt;/span&gt; as $k =&amp;gt; $orderBy) {&lt;/li&gt;
	&lt;li&gt;$e = explode(&apos;, &apos;, $orderBy);&lt;/li&gt;
	&lt;li&gt;unset($this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;orderby&amp;#39;&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;$k&amp;#93;&lt;/span&gt;);&lt;/li&gt;
	&lt;li&gt;foreach ($e as $v) 
{
-                $this-&amp;gt;_sqlParts[&apos;orderby&apos;][] = $v;
-            }&lt;/li&gt;
	&lt;li&gt;}&lt;br/&gt;
-&lt;/li&gt;
	&lt;li&gt;// Add the default orderBy statements defined in the relationships and table classes&lt;/li&gt;
	&lt;li&gt;// Only do this for SELECT queries&lt;/li&gt;
	&lt;li&gt;if ($this-&amp;gt;_type === self::SELECT) {&lt;/li&gt;
	&lt;li&gt;foreach ($this-&amp;gt;_queryComponents as $alias =&amp;gt; $map) {&lt;/li&gt;
	&lt;li&gt;$sqlAlias = $this-&amp;gt;getSqlTableAlias($alias);&lt;/li&gt;
	&lt;li&gt;if (isset($map&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;relation&amp;#39;&amp;#93;&lt;/span&gt;)) {&lt;/li&gt;
	&lt;li&gt;$orderBy = $map&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;relation&amp;#39;&amp;#93;&lt;/span&gt;-&amp;gt;getOrderByStatement($sqlAlias, true);&lt;/li&gt;
	&lt;li&gt;if ($orderBy == $map&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;relation&amp;#39;&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;orderBy&amp;#39;&amp;#93;&lt;/span&gt;) {&lt;/li&gt;
	&lt;li&gt;if (isset($map&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;ref&amp;#39;&amp;#93;&lt;/span&gt;)) 
{
-                            $orderBy = $map[&apos;relation&apos;][&apos;refTable&apos;]-&amp;gt;processOrderBy($sqlAlias, $map[&apos;relation&apos;][&apos;orderBy&apos;], true);
-                        }
&lt;p&gt; else &lt;/p&gt;
{
-                            $orderBy = null;
-                        }&lt;/li&gt;
	&lt;li&gt;}&lt;/li&gt;
	&lt;li&gt;} else 
{
-                    $orderBy = $map[&apos;table&apos;]-&amp;gt;getOrderByStatement($sqlAlias, true);
-                }
&lt;p&gt;-&lt;/p&gt;&lt;/li&gt;
	&lt;li&gt;if ($orderBy) {&lt;/li&gt;
	&lt;li&gt;$e = explode(&apos;,&apos;, $orderBy);&lt;/li&gt;
	&lt;li&gt;$e = array_map(&apos;trim&apos;, $e);&lt;/li&gt;
	&lt;li&gt;foreach ($e as $v) {&lt;/li&gt;
	&lt;li&gt;if ( ! in_array($v, $this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;orderby&amp;#39;&amp;#93;&lt;/span&gt;)) 
{
-                            $this-&amp;gt;_sqlParts[&apos;orderby&apos;][] = $v;
-                        }&lt;/li&gt;
	&lt;li&gt;}&lt;/li&gt;
	&lt;li&gt;}&lt;/li&gt;
	&lt;li&gt;}&lt;/li&gt;
	&lt;li&gt;}&lt;br/&gt;
-&lt;br/&gt;
         $q .= ( ! empty($this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;groupby&amp;#39;&amp;#93;&lt;/span&gt;)) ? &apos; GROUP BY &apos; . implode(&apos;, &apos;, $this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;groupby&amp;#39;&amp;#93;&lt;/span&gt;)  : &apos;&apos;;&lt;br/&gt;
         $q .= ( ! empty($this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;having&amp;#39;&amp;#93;&lt;/span&gt;)) ?  &apos; HAVING &apos;   . implode(&apos; AND &apos;, $this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;having&amp;#39;&amp;#93;&lt;/span&gt;): &apos;&apos;;&lt;br/&gt;
         $q .= ( ! empty($this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;orderby&amp;#39;&amp;#93;&lt;/span&gt;)) ? &apos; ORDER BY &apos; . implode(&apos;, &apos;, $this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;orderby&amp;#39;&amp;#93;&lt;/span&gt;)  : &apos;&apos;;&lt;br/&gt;
@@ -1396,7 +1396,7 @@&lt;br/&gt;
             $subquery = &apos;SELECT DISTINCT &apos;;&lt;br/&gt;
         }&lt;br/&gt;
         $subquery .= $this-&amp;gt;_conn-&amp;gt;quoteIdentifier($primaryKey);&lt;br/&gt;
-&lt;br/&gt;
+        &lt;br/&gt;
         // pgsql &amp;amp; oracle need the order by fields to be preserved in select clause&lt;br/&gt;
         if ($driverName == &apos;pgsql&apos; || $driverName == &apos;oracle&apos; || $driverName == &apos;oci&apos; || $driverName == &apos;mssql&apos; || $driverName == &apos;odbc&apos;) {&lt;br/&gt;
             foreach ($this-&amp;gt;_sqlParts&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;orderby&amp;#39;&amp;#93;&lt;/span&gt; as $part) 
&lt;div class=&quot;error&quot;&gt;&lt;span class=&quot;error&quot;&gt;Unknown macro: {@@ -1420,7 +1420,7 @@                         // don&amp;#39;t add primarykey column (its already in the select clause)                         if ($part !== $primaryKey) {
                             $subquery .= &apos;, &apos; . $partOriginal;
-                        }+                        }&lt;/span&gt; &lt;/div&gt;
&lt;p&gt; &lt;br/&gt;
                     }&lt;br/&gt;
                 }&lt;br/&gt;
             }&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Property changes on: Query.php&lt;br/&gt;
___________________________________________________________________&lt;br/&gt;
Deleted: svn:keywords&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Id Revision&lt;br/&gt;
Deleted: svn:eol-style&lt;/li&gt;
	&lt;li&gt;LF&lt;/li&gt;
&lt;/ul&gt;
</comment>
                    <comment id="14594" author="angrygreenfrogs" created="Fri, 22 Oct 2010 03:05:58 +0000"  >&lt;p&gt;Diff file&lt;/p&gt;</comment>
                    <comment id="14700" author="angrygreenfrogs" created="Wed, 10 Nov 2010 01:41:14 +0000"  >&lt;p&gt;patch -p0 ./libs/doctrine/Doctrine/Query.php ./Doctrine_Query.php.ORDERBY.patch&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10856" name="Doctrine_Query.php.ORDERBY.patch" size="5166" author="angrygreenfrogs" created="Wed, 10 Nov 2010 01:41:14 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-312] Doctrine_Pager query &quot;influences&quot; Doctrine::getTable() query</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-312</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;When I use the same procedure without Doctrine_Pager everything works fine, with Doctrine_Pager the behavior of later queries is strange. Example:&lt;br/&gt;
----------------WORKING:&lt;br/&gt;
1. I fetch list &lt;br/&gt;
Doctrine_Query::create()&lt;del&gt;&amp;gt;select(&apos;z.&lt;b&gt;,s.&lt;/b&gt;,o.*,u.jmeno as Vlo&#382;il,k.nazev_cs as Kategorie&apos;)&lt;/del&gt;&amp;gt;from(&apos;ShopZbozi z,z.Obrazek o,z.Soubor s,z.Uzivatel u,z.ShopKategorie k&apos;)&lt;del&gt;&amp;gt;orderby(&apos;z.nazev_cs ASC&apos;)&lt;/del&gt;&amp;gt;fetchArray(); &lt;/p&gt;

&lt;p&gt;2. I fetch a row to edit independently on the list above&lt;br/&gt;
$object = Doctrine::getTable(&apos;ShopZbozi&apos;)-&amp;gt;find(123);&lt;/p&gt;

&lt;p&gt;3. edit properties of the object...&lt;/p&gt;

&lt;p&gt;4. $object-&amp;gt;replace();&lt;br/&gt;
the object is fetched with no related objects like &lt;span class=&quot;error&quot;&gt;&amp;#91;Uzivatel&amp;#93;&lt;/span&gt; or &lt;span class=&quot;error&quot;&gt;&amp;#91;Soubor&amp;#93;&lt;/span&gt;, so when I change for example $object-&amp;gt;iduzivatel (related Uzivatel object id) and save it is OK&lt;/p&gt;

&lt;p&gt;----------------BROKEN:&lt;br/&gt;
1. I fetch list in Pager&lt;br/&gt;
new Doctrine_Pager(Doctrine_Query::create()&lt;del&gt;&amp;gt;select(&apos;z.&lt;b&gt;,s.&lt;/b&gt;,o.*,u.jmeno as Vlo&#382;il,k.nazev_cs as Kategorie&apos;)&lt;/del&gt;&amp;gt;from(&apos;ShopZbozi z,z.Obrazek o,z.Soubor s,z.Uzivatel u,z.ShopKategorie k&apos;)&lt;del&gt;&amp;gt;orderby(&apos;z.nazev_cs ASC&apos;),$this&lt;/del&gt;&amp;gt;page,$this-&amp;gt;perpage);&lt;/p&gt;

&lt;p&gt;2. I fetch a row to edit independently on the list above    (in contrast to the first working example this $object is fetched with EMPTY RELATION OBJECTS, which causes inserting empty new rows when calling -&amp;gt;replace())&lt;br/&gt;
$object = Doctrine::getTable(&apos;ShopZbozi&apos;)-&amp;gt;find(123);&lt;/p&gt;

&lt;p&gt;3. edit properties of the object...&lt;/p&gt;

&lt;p&gt;4. $object-&amp;gt;replace(); &lt;br/&gt;
-&amp;gt; the $object has all the related object fetched as it was defined in the list in Pager - like it was used as a template for getTable and when -&amp;gt;replace() - new empty related objects are inserted in DB.&lt;/p&gt;


&lt;p&gt;I&apos;ve been using Doctrine for I guess 2 years now and I believe this bug/strange behavior has always been there.&lt;br/&gt;
Maybe I&apos;m wrong and it is not a bug, but the behavior is strange and it took me really long to find where the problem is and I still don&apos;t know how to use pager without influencing the later queries.&lt;br/&gt;
Thanx John Mathew&lt;/p&gt;</description>
                <environment>Debian testing squeeze 32 bit.</environment>
            <key id="10544">DC-312</key>
            <summary>Doctrine_Pager query &quot;influences&quot; Doctrine::getTable() query</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="seiffs">Jan Matousek</reporter>
                        <labels>
                    </labels>
                <created>Wed, 2 Dec 2009 10:19:08 +0000</created>
                <updated>Wed, 2 Dec 2009 10:20:19 +0000</updated>
                                    <version>1.2.0</version>
                                                <component>Pager</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-188] Pager breaks when HAVING clause references existing table column</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-188</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Pager breaks when HAVING clause references any existing table column.&lt;/p&gt;

&lt;p&gt;Query used:&lt;/p&gt;

&lt;p&gt;        $q = Doctrine_Query::create()&lt;br/&gt;
             -&amp;gt;select(&quot;u.id, u.first_name, u.last_name, u.is_active&quot;)&lt;br/&gt;
             -&amp;gt;addSelect(&apos;COUNT(u.id) as rolecount&apos;)&lt;br/&gt;
             -&amp;gt;from(&apos;User u&apos;)&lt;br/&gt;
             -&amp;gt;leftJoin(&apos;u.Roles r&apos;)&lt;br/&gt;
             -&amp;gt;groupBy(&apos;u.id&apos;)&lt;br/&gt;
             -&amp;gt;having(&quot;rolecount &amp;gt; 2 and u.is_active = 1&quot;);&lt;/p&gt;

&lt;p&gt;Execution of query by itself works fine (eg via execute(), fetch...)&lt;/p&gt;

&lt;p&gt;When putting this query in a Doctrine_Pager, error outputs:&lt;/p&gt;

&lt;p&gt;        $pager = new Doctrine_Pager(&lt;br/&gt;
              $q,&lt;br/&gt;
              $currentPage, &lt;br/&gt;
              $resultsPerPage &lt;br/&gt;
        );&lt;/p&gt;

&lt;p&gt;        $pager-&amp;gt;execute();&lt;/p&gt;


&lt;p&gt;Error Received:&lt;br/&gt;
SQLSTATE&lt;span class=&quot;error&quot;&gt;&amp;#91;42S22&amp;#93;&lt;/span&gt;: Column not found: 1054 Unknown column &apos;u.is_active&apos; in &apos;having clause&apos;&lt;/p&gt;</description>
                <environment>Local: Windows/Cygwin/XAMPP&lt;br/&gt;
Stage &amp;amp; Prod:  CentOS&lt;br/&gt;
Apache / MySQL&lt;br/&gt;
Framework:  Zend&lt;br/&gt;
</environment>
            <key id="10340">DC-188</key>
            <summary>Pager breaks when HAVING clause references existing table column</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="benbac">Benedict Bacayon</reporter>
                        <labels>
                    </labels>
                <created>Wed, 4 Nov 2009 21:50:18 +0000</created>
                <updated>Tue, 20 Jul 2010 01:14:31 +0000</updated>
                                    <version>1.1.5</version>
                                                <component>Pager</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="13615" author="ryan" created="Tue, 20 Jul 2010 01:12:54 +0000"  >&lt;p&gt;a quick fix for this is to enclose the field in parentheses when selecting it, then use an alias to reference it inside the having clause. eg &lt;/p&gt;

&lt;p&gt;$q = Doctrine_Query::create()&lt;br/&gt;
-&amp;gt;select(&quot;u.id, u.first_name, u.last_name, (u.is_active) u_is_active&quot;)&lt;br/&gt;
-&amp;gt;addSelect(&apos;COUNT(u.id) as rolecount&apos;)&lt;br/&gt;
-&amp;gt;from(&apos;User u&apos;)&lt;br/&gt;
-&amp;gt;leftJoin(&apos;u.Roles r&apos;)&lt;br/&gt;
-&amp;gt;groupBy(&apos;u.id&apos;)&lt;br/&gt;
-&amp;gt;having(&quot;rolecount &amp;gt; 2 and u_is_active = 1&quot;);&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-544] Doctrine_Pager bug with Oracle. getNumResults doesn&apos;t return the correct number of records</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-544</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;The function getNumResults() doesn&apos;t work correctly.&lt;/p&gt;

&lt;p&gt;This is my model class&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 ReviewListTable &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; Doctrine_Table
{
 &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getAvailable()
 {
   &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;createQuery()
   -&amp;gt;select(&apos;DISTINCT(to_char(file_date, \&apos;YYYY-MM-DD\&apos;)) fdate&apos;)
   -&amp;gt;orderBy(&apos;fdate DESC&apos;);
 }
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If i execute this fonction, the number of record is 31. If i use the Pager, the result is 5744 records&lt;/p&gt;

&lt;p&gt;Controler:&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;pager = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Pager(
                           Doctrine_Core::getTable(&apos;ReviewList&apos;)-&amp;gt;getAvailable(),
                           $request-&amp;gt;getParameter(&apos;page&apos;, 1),
                           20);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;


&lt;p&gt;View:&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;$rs = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;pager-&amp;gt;execute();
echo $pager-&amp;gt;getNumResults();
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
            <key id="10993">DC-544</key>
            <summary>Doctrine_Pager bug with Oracle. getNumResults doesn&apos;t return the correct number of records</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="garfield-fr">Bertrand Zuchuat</reporter>
                        <labels>
                    </labels>
                <created>Thu, 4 Mar 2010 04:29:53 +0000</created>
                <updated>Thu, 18 Mar 2010 08:02:39 +0000</updated>
                                    <version>1.2.1</version>
                                                <component>Pager</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="12235" author="jwage" created="Mon, 15 Mar 2010 16:20:49 +0000"  >&lt;p&gt;Hmm. I don&apos;t quite understand. Can you make a test case?&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10492" name="DC544TestCase.php" size="4092" author="garfield-fr" created="Thu, 18 Mar 2010 08:02:39 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-739] Pager returns incorrect page number when constructed on query with HAVING</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-739</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;//method returns those categories that have any products, it returns 3 records&lt;br/&gt;
public function getCategoriesWithProductsQuery()&lt;/p&gt;
 {
   $query = $this-&amp;gt;createQuery(&apos;z&apos;)-&amp;gt;select( &apos;z.*, COUNT(p.id) prod_number&apos; )
          -&amp;gt;leftJoin( &apos;z.AdvertiseProducts p&apos; )-&amp;gt;groupBy( &apos;z.id&apos; )-&amp;gt;having(&apos;prod_number &amp;gt; 0&apos;);

   return $query;
 }

&lt;p&gt;//but when i do count() on created pager it returns 8 records (which is equal to categories in my database):&lt;/p&gt;

&lt;p&gt;$doctrinePager = $this-&amp;gt;getServiceContainer()&lt;br/&gt;
-&amp;gt;setParameter(&apos;doctrine_pager.model&apos;, &apos;ZwCategory&apos;)&lt;br/&gt;
-&amp;gt;getService(&apos;doctrine_pager&apos;)&lt;br/&gt;
&lt;del&gt;&amp;gt;setMaxPerPage($this&lt;/del&gt;&amp;gt;maxPerPage)&lt;br/&gt;
-&amp;gt;setQuery($query)&lt;br/&gt;
&lt;del&gt;&amp;gt;setPage(null === $page ? $this&lt;/del&gt;&amp;gt;page : $page)&lt;br/&gt;
-&amp;gt;init();&lt;br/&gt;
var_dump(count($doctrinePager));&lt;/p&gt;

&lt;p&gt;//pager works, but it &quot;thinks&quot; that there are more pages than in reality. with maxPerPage = 2, it thinks that there are 4 pages, but looking at query result it //should be only 2 pages.&lt;/p&gt;</description>
                <environment>Ubuntu 9.10, &lt;br/&gt;
Apache/MySQL,&lt;br/&gt;
Framework: Symfony 1.4&lt;br/&gt;
</environment>
            <key id="11499">DC-739</key>
            <summary>Pager returns incorrect page number when constructed on query with HAVING</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="pawelbaranski">Pawe&#322; Bara&#324;ski</reporter>
                        <labels>
                    </labels>
                <created>Wed, 16 Jun 2010 03:14:11 +0000</created>
                <updated>Wed, 16 Jun 2010 03:16:39 +0000</updated>
                                    <version>1.2.2</version>
                                                <component>Pager</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>