ZF-3349: $table->find() method miss matching rows

Issue Type: Bug Created: 2008-05-29T04:45:35.000+0000 Last Updated: 2009-08-25T15:50:40.000+0000 Status: Resolved Fix version(s): - 1.9.3 (22/Sep/09)

Reporter: Remy Damour (remy215) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db_Table

Related issues: - ZF-7653



API Doc says that .find() method accepts arrays of arguments (one per primary key field), but it does not specify that these arrays MUST NOT be hash, otherwise array entries are skipped and .find() does not return all matching rows! Very serious bug!

Ex: $id = array(0=>1, 1=>2, 99=>3); mytable.find($id) will skip value '3' because its key is not 2. Generated $whereClause is:

<pre class="highlight">
where expected clause is:

This comes from the following code, in Zend_Db_Table_Abstract, public function find():

<pre class="highlight">
            for ($i = 0; $i < count($keyValues); ++$i) {
                $whereList[$i][$keyPosition] = $keyValues[$i];

which could be replaced by:

<pre class="highlight">
           $i = 0;
            foreach ($keyValues as $v) {
                $whereList[$i++][$keyPosition] = $v;

Great framework anyway! Keep up, guys! Thx


Posted by wanlei (shannonlee) on 2008-05-29T23:05:31.000+0000

The arguments array provide to find() need no keys. So , I think , a better way is to use array_values() in find() method to evevy arguments array, make sure they all index by 0 , 1 , 2 .....

Posted by Wil Sinclair (wil) on 2008-06-09T09:52:19.000+0000

Please evaluate and fix/categorize as necessary.

Posted by Josh Butts (jimbojsb) on 2009-08-17T11:47:56.000+0000

I believe this is not an issue, and should be resolved as such

Posted by Ralph Schindler (ralph) on 2009-08-17T13:59:21.000+0000

While i think this could go either way, I think its best to perhaps change the behavior under the hood to use array_values() instead of using the for loop. This would ensure that only values are used.

Changing to "Trivial", "Nice To Have", can go in "Next Mini Release", about 30m of real work

Posted by Ralph Schindler (ralph) on 2009-08-25T15:50:40.000+0000

Fixed in trunk in r17815 and in release branch 1.9 in r17816

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.