Explorar el Código

ZF-3349
- Fixed issue with assoc. keys being passed to Zend_Db_Table_Abstract::find()

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17815 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph hace 16 años
padre
commit
7aac8512c7
Se han modificado 2 ficheros con 17 adiciones y 3 borrados
  1. 5 3
      library/Zend/Db/Table/Abstract.php
  2. 12 0
      tests/Zend/Db/Table/TestCommon.php

+ 5 - 3
library/Zend/Db/Table/Abstract.php

@@ -1228,6 +1228,7 @@ abstract class Zend_Db_Table_Abstract
         $whereList = array();
         $numberTerms = 0;
         foreach ($args as $keyPosition => $keyValues) {
+            $keyValuesCount = count($keyValues);
             // Coerce the values to an array.
             // Don't simply typecast to array, because the values
             // might be Zend_Db_Expr objects.
@@ -1235,12 +1236,13 @@ abstract class Zend_Db_Table_Abstract
                 $keyValues = array($keyValues);
             }
             if ($numberTerms == 0) {
-                $numberTerms = count($keyValues);
-            } else if (count($keyValues) != $numberTerms) {
+                $numberTerms = $keyValuesCount;
+            } else if ($keyValuesCount != $numberTerms) {
                 require_once 'Zend/Db/Table/Exception.php';
                 throw new Zend_Db_Table_Exception("Missing value(s) for the primary key");
             }
-            for ($i = 0; $i < count($keyValues); ++$i) {
+            $keyValues = array_values($keyValues);
+            for ($i = 0; $i < $keyValuesCount; ++$i) {
                 if (!isset($whereList[$i])) {
                     $whereList[$i] = array();
                 }

+ 12 - 0
tests/Zend/Db/Table/TestCommon.php

@@ -627,6 +627,18 @@ abstract class Zend_Db_Table_TestCommon extends Zend_Db_Table_TestSetup
         }
     }
 
+    /**
+     * @group ZF-3349
+     */
+    public function testTableFindMultipleRowsWithKeys()
+    {
+        $table = $this->_table['products'];
+        $rowset = $table->find(array(0 => 1, 1 => 2, 99 => 3));
+        $this->assertType('Zend_Db_Table_Rowset_Abstract', $rowset,
+            'Expecting object of type Zend_Db_Table_Rowset_Abstract, got '.get_class($rowset));
+        $this->assertEquals(3, count($rowset));
+    }
+    
     public function testTableInsert()
     {
         $table = $this->_table['bugs'];