Zend Framework

$table->find() method miss matching rows

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Trivial Trivial
  • Resolution: Fixed
  • Affects Version/s: 1.5.1
  • Fix Version/s: 1.9.3
  • Component/s: Zend_Db_Table
  • Labels:
    None
  • Fix Version Priority:
    Nice to Have

Description

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:

((`id` = 1) OR (`id` = 2) OR (`id` = 0))

where expected clause is:

((`id` = 1) OR (`id` = 2) OR (`id` = 3))

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

for ($i = 0; $i < count($keyValues); ++$i) {
                $whereList[$i][$keyPosition] = $keyValues[$i];
            }

which could be replaced by:

$i = 0;
            foreach ($keyValues as $v) {
                $whereList[$i++][$keyPosition] = $v;
            }

Great framework anyway!
Keep up, guys!
Thx

Issue Links

Activity

Hide
wanlei added a comment -

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 .....

Show
wanlei added a comment - 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 .....
Hide
Wil Sinclair added a comment -

Please evaluate and fix/categorize as necessary.

Show
Wil Sinclair added a comment - Please evaluate and fix/categorize as necessary.
Hide
Josh Butts added a comment -

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

Show
Josh Butts added a comment - I believe this is not an issue, and should be resolved as such
Hide
Ralph Schindler added a comment -

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

Show
Ralph Schindler added a comment - 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
Hide
Ralph Schindler added a comment -

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

Show
Ralph Schindler added a comment - Fixed in trunk in r17815 and in release branch 1.9 in r17816

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
30m
Original Estimate - 30 minutes
Remaining:
30m
Remaining Estimate - 30 minutes
Logged:
Not Specified
Time Spent - Not Specified