<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Sat May 25 18:20:52 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-585/DC-585.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-585] Hydrate Array does not return full array, when Hydrate Scalar does</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-585</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Description : Upon hydrating as array I will receive one row returned.  If I am to hydrate as Scalar, I will get 200+ rows.  Also, if i echo the sql ($q-&amp;gt;getSqlQuery()) and run that raw, it will also return around 200+ rows.&lt;/p&gt;


&lt;p&gt;$q = Doctrine_Query::create()&lt;br/&gt;
            -&amp;gt;select(&apos;DISTINCT(co.name) AS field, co.name AS value&apos;)&lt;br/&gt;
            -&amp;gt;from(&apos;Model_Country co&apos;)&lt;br/&gt;
            -&amp;gt;leftJoin(&apos;co.City ci&apos;);&lt;/p&gt;

&lt;p&gt;//here we will get only the first row&lt;br/&gt;
$results = $q-&amp;gt;execute(array(), Doctrine::HYDRATE_ARRAY);&lt;/p&gt;

&lt;p&gt;//Here we will get all 200+ rows&lt;br/&gt;
$results = $q-&amp;gt;execute(array(), Doctrine::HYDRATE_SCALAR);&lt;/p&gt;

&lt;p&gt;I have yet to dig to deep into this, but if it is indeed a bug, my guess is it is in Doctrine_Hydrator_Graph::hydrateResultSet()&lt;/p&gt;

&lt;p&gt;I can provide more data if needed.&lt;/p&gt;
</description>
                <environment>OS : Ubuntu 9.04&lt;br/&gt;
PHP : PHP 5.2.6-3ubuntu4.5</environment>
            <key id="11085">DC-585</key>
            <summary>Hydrate Array does not return full array, when Hydrate Scalar does</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="jwage">Jonathan H. Wage</assignee>
                                <reporter username="solomonjames">James Solomon</reporter>
                        <labels>
                    </labels>
                <created>Thu, 18 Mar 2010 14:36:24 +0000</created>
                <updated>Fri, 2 Mar 2012 17:44:46 +0000</updated>
                                                                            <due></due>
                    <votes>4</votes>
                        <watches>5</watches>
                        <comments>
                    <comment id="12339" author="solomonjames" created="Thu, 18 Mar 2010 15:22:52 +0000"  >&lt;p&gt;I have found this in the google group, and he provides more detailed info, and appears to be the same exact issue : &lt;a href=&quot;http://groups.google.com/group/doctrine-user/msg/8e4a8a673428fff0&quot; class=&quot;external-link&quot;&gt;http://groups.google.com/group/doctrine-user/msg/8e4a8a673428fff0&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="12340" author="solomonjames" created="Thu, 18 Mar 2010 17:30:26 +0000"  >&lt;p&gt;seems to be another similar issue here : &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-328&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/jira/browse/DC-328&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="13013" author="jagalan" created="Wed, 19 May 2010 12:15:32 +0000"  >&lt;p&gt;I&apos;m having that problem and I taked a look into the code, found this:&lt;/p&gt;

&lt;p&gt;I have a query that looks like this:&lt;br/&gt;
 $q = Doctrine_Query::create()&lt;br/&gt;
-&amp;gt;select(&apos;af.id as id, af.user_id as user&apos;)&lt;br/&gt;
-&amp;gt;from(&apos;ActivityFeed af&apos;)&lt;br/&gt;
-&amp;gt;innerJoin(&apos;af.user as afu&apos;)&lt;br/&gt;
-&amp;gt;orderBy(&apos;af.time DESC&apos;);&lt;/p&gt;

&lt;p&gt;The sql query without aliases in SELECT or without join is built that way:&lt;br/&gt;
SELECT a.id AS a_&lt;em&gt;id, a.user_id AS a&lt;/em&gt;_user_id ... -&amp;gt; This is returning all the records&lt;/p&gt;

&lt;p&gt;The sql query with aliases in SELECT is built that way:&lt;br/&gt;
SELECT a.id AS a_&lt;em&gt;0, a.user_id AS a&lt;/em&gt;_1 FROM ... -&amp;gt; This is returning only one record&lt;/p&gt;

&lt;p&gt;In Doctrine_Hydrator_Graph::_gatherRowData, line 288 there&apos;s the following call:&lt;/p&gt;

&lt;p&gt;$fieldName = $table-&amp;gt;getFieldName($last);&lt;br/&gt;
Where $last is the last part of the column alias, for example &quot;0&quot; in &quot;a__0&quot;. This way the call asks the table for the name of the &quot;0&quot; field and the table returns &quot;0&quot; so I think we&apos;re not getting the right field name (it must be &quot;id&quot;).&lt;/p&gt;

&lt;p&gt;I&apos;m not understanding the whole hydration process but replacing&lt;/p&gt;

&lt;p&gt;$fieldName = $table-&amp;gt;getFieldName($last);&lt;/p&gt;

&lt;p&gt;with:&lt;/p&gt;

&lt;p&gt;if(isset($this-&amp;gt;_queryComponents[ $cache&lt;span class=&quot;error&quot;&gt;&amp;#91;$key&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;dqlAlias&amp;#39;&amp;#93;&lt;/span&gt;]&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;agg&amp;#39;&amp;#93;&lt;/span&gt;)) {&lt;br/&gt;
              $fieldName = $table-&amp;gt;getFieldName($this-&amp;gt;_queryComponents[ $cache&lt;span class=&quot;error&quot;&gt;&amp;#91;$key&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;dqlAlias&amp;#39;&amp;#93;&lt;/span&gt;]&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;agg&amp;#39;&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;$last&amp;#93;&lt;/span&gt;);&lt;br/&gt;
} else {&lt;br/&gt;
                $fieldName = $table-&amp;gt;getFieldName($last);&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;solves the problem almost in my case.&lt;/p&gt;

&lt;p&gt;Hope it will help to solve the issue. &lt;/p&gt;</comment>
                    <comment id="13190" author="jwage" created="Tue, 8 Jun 2010 14:39:57 +0000"  >&lt;p&gt;It seems the suggested change causes many failures in our test suite. Can you give it a try and confirm?&lt;/p&gt;</comment>
                    <comment id="13721" author="ben.davies" created="Wed, 28 Jul 2010 12:45:51 +0000"  >&lt;p&gt;Just commenting to say that I can confirm this bug exists. It&apos;s happening for me too.  &lt;br/&gt;
I will try and dig deeper when I have some time.&lt;/p&gt;</comment>
                    <comment id="14129" author="jagalan" created="Sat, 28 Aug 2010 10:42:31 +0000"  >&lt;p&gt;As the error is located in Doctrine_Hydrator_Graph, HYDRATE_RECORD has the same behaviour.&lt;/p&gt;

&lt;p&gt;I&apos;m trying to find a solution.&lt;/p&gt;</comment>
                    <comment id="14194" author="ben.davies" created="Tue, 31 Aug 2010 10:21:15 +0000"  >&lt;p&gt;This only occurs if your alias your identifier field.&lt;br/&gt;
Doctrine needs to know which field is the identifier to hydrate records.&lt;br/&gt;
The identifier aliases is formed to x__0, and then, as other commented has found.&lt;br/&gt;
Doctrine then has no way of determining which field is the identifier.&lt;/p&gt;</comment>
                    <comment id="14569" author="enrico" created="Fri, 15 Oct 2010 04:03:09 +0000"  >&lt;p&gt;Hi everybody,&lt;/p&gt;

&lt;p&gt;we really need a unit test here. The provided patch breaks all aliased queries in our application. I will provide a patch and it hopefully solves your problem Juan. If not, please provide more information or add another test-method to the provided unit test.&lt;/p&gt;

&lt;p&gt;I had to rewrite some of the unit tests cause the order of the fields in the generated sql statement has changed due the provided patch.&lt;/p&gt;

&lt;p&gt;Enrico&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://github.com/doctrine/doctrine1/commit/e3ae69c2260dae6dfbceb4e24138b2379f3da2e6#commitcomment-169495&quot; class=&quot;external-link&quot;&gt;http://github.com/doctrine/doctrine1/commit/e3ae69c2260dae6dfbceb4e24138b2379f3da2e6#commitcomment-169495&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;http://github.com/estahn/doctrine1/tree/DC-585&quot; class=&quot;external-link&quot;&gt;http://github.com/estahn/doctrine1/tree/DC-585&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="15444" author="loops" created="Fri, 4 Mar 2011 03:56:07 +0000"  >&lt;p&gt;Hi,&lt;/p&gt;


&lt;p&gt;I have a little issue with this bug report...&lt;/p&gt;

&lt;p&gt;I&apos;m currently using Doctrine 1.2 at revision 7691, and I&apos;ve encounter a bug when select the primary key of a model with a custom alias (typically &lt;em&gt;$query-&amp;gt;addSelect( &apos;r.id as my_id&apos; )&lt;/em&gt;), the issue was that Doctrine automatically add &lt;em&gt;`r`.```id``` AS `r&lt;/em&gt;_&lt;em&gt;1`&lt;/em&gt; to the select clause, in addition to the correct &lt;em&gt;`r`.`id` AS `r&lt;/em&gt;_&lt;em&gt;1`&lt;/em&gt; part.&lt;/p&gt;

&lt;p&gt;So, I&apos;ve browse the code to finally found where does this strange thing comes from, and I&apos;ve found it on Doctrine_Query::parseSelect() method, just at the line 663:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;                // Fix for &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-585&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/jira/browse/DC-585&lt;/a&gt;&lt;br/&gt;
                // Add selected columns to pending fields&lt;br/&gt;
                if (preg_match(&apos;/^(&lt;span class=&quot;error&quot;&gt;&amp;#91;^\(&amp;#93;&lt;/span&gt;+)\.(\&apos;?)(.*?)(\&apos;?)$/&apos;, $expression, $field)) {&lt;br/&gt;
                    $this-&amp;gt;_pendingFields&lt;span class=&quot;error&quot;&gt;&amp;#91;$componentAlias&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;$alias&amp;#93;&lt;/span&gt; = $field&lt;span class=&quot;error&quot;&gt;&amp;#91;3&amp;#93;&lt;/span&gt;;&lt;br/&gt;
                }&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;So I&apos;m wonder : where does this patch is related to this bug report?&lt;/p&gt;


&lt;p&gt;Whatever, the bug I&apos;ve encounter is very simple : the regular expression that extract the field name takes care about &lt;em&gt;&apos;&lt;/em&gt; but not &lt;em&gt;&#180;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;You will find a patch for the bug &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-585&quot; title=&quot;Hydrate Array does not return full array, when Hydrate Scalar does&quot;&gt;DC-585&lt;/a&gt;-b in a few minutes... This patch just make the regular expression taking account of &lt;em&gt;&apos;&lt;/em&gt; and &lt;em&gt;&#180;&lt;/em&gt; and also remove all useless parentheses in expression (by this way PCRE get less matches to capture and we can earn some precious microseconds).&lt;/p&gt;

&lt;p&gt;Also, this patch should be completed because the query still have two &lt;em&gt;`r`.`id` AS `r&lt;/em&gt;_&lt;em&gt;1`&lt;/em&gt; parts, that may cause some other issues with some databases...&lt;/p&gt;

&lt;p&gt;IMPORTANT NOTE: The previous revision 7674 of Doctrine_Query does not cause the bug encounter with the few lines of code above, just because they were not there. They really must be review.&lt;/p&gt;



&lt;p&gt;Loops&lt;/p&gt;</comment>
                    <comment id="15750" author="loops" created="Thu, 28 Apr 2011 05:03:36 +0000"  >&lt;p&gt;Damn, the bug above was corrected during a few weeks and comes back with the new branch of Doctrine 1.2.14.&lt;/p&gt;

&lt;p&gt;Does anybody can re-apply the corrective patch (renamed &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-585&quot; title=&quot;Hydrate Array does not return full array, when Hydrate Scalar does&quot;&gt;DC-585&lt;/a&gt;-c), please ?&lt;/p&gt;

&lt;p&gt;I repeat it agin, but these few lines of code really need to be review.&lt;/p&gt;

&lt;p&gt;Loops&lt;/p&gt;</comment>
                    <comment id="17241" author="knagode" created="Fri, 13 Jan 2012 20:08:54 +0000"  >&lt;p&gt;I also have this problem .. Anyone know howt o fix it?&lt;/p&gt;

&lt;p&gt;$query-&amp;gt;execute(array(), Doctrine::HYDRATE_ARRAY); // returns one row only&lt;br/&gt;
$query-&amp;gt;execute(array(), Doctrine::HYDRATE_RECORD); // returns one row only&lt;/p&gt;

&lt;p&gt;$query-&amp;gt;execute(array(), Doctrine::HYDRATE_SCALAR); // returns result as expected&lt;/p&gt;</comment>
                    <comment id="17242" author="knagode" created="Sat, 14 Jan 2012 00:40:36 +0000"  >&lt;p&gt;I found solution for my  problem: &lt;/p&gt;

&lt;p&gt;Table had ID field but it was not primary key.  When I deleted this column, doctrine started to work as expected. &lt;/p&gt;</comment>
                    <comment id="17491" author="lacton" created="Fri, 2 Mar 2012 17:44:46 +0000"  >&lt;p&gt;I have run into the same issue.&lt;/p&gt;

&lt;p&gt;Using the default hydration, I get only one record.&lt;/p&gt;

&lt;p&gt;Using &quot;$query-&amp;gt;execute(array(), Doctrine::HYDRATE_SCALAR);&quot;, I get all the expected records.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10950" name="Doctrine-DC-585-b.patch" size="721" author="loops" created="Fri, 4 Mar 2011 04:04:39 +0000" />
                    <attachment id="10976" name="Doctrine-DC-585-c.patch" size="718" author="loops" created="Thu, 28 Apr 2011 05:18:22 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>