Browse Source

ZF-5953: Zend_Db_Select: Support multiple join columns in joinUsing

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24833 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan 13 năm trước cách đây
mục cha
commit
52e0ce107e
2 tập tin đã thay đổi với 25 bổ sung3 xóa
  1. 7 3
      library/Zend/Db/Select.php
  2. 18 0
      tests/Zend/Db/Select/TestCommon.php

+ 7 - 3
library/Zend/Db/Select.php

@@ -880,9 +880,13 @@ class Zend_Db_Select
         $join  = $this->_adapter->quoteIdentifier(key($this->_parts[self::FROM]), true);
         $from  = $this->_adapter->quoteIdentifier($this->_uniqueCorrelation($name), true);
 
-        $cond1 = $from . '.' . $cond;
-        $cond2 = $join . '.' . $cond;
-        $cond  = $cond1 . ' = ' . $cond2;
+        $joinCond = array();
+        foreach ((array)$cond as $fieldName) {
+            $cond1 = $from . '.' . $fieldName;
+            $cond2 = $join . '.' . $fieldName;
+            $joinCond[]  = $cond1 . ' = ' . $cond2;
+        }
+        $cond = implode(' '.self::SQL_AND.' ', $joinCond);
 
         return $this->_join($type, $name, $cond, $cols, $schema);
     }

+ 18 - 0
tests/Zend/Db/Select/TestCommon.php

@@ -1712,6 +1712,24 @@ abstract class Zend_Db_Select_TestCommon extends Zend_Db_TestSetup
     }
 
     /**
+     * @group ZF-5953
+     */
+    public function testJoinUsingAllowsSpecifyingMultipleColumnsViaAnArray()
+    {
+        $table_A = $this->_db->quoteTableAs('A');
+        $table_B = $this->_db->quoteTableAs('B');
+        $colOne  = $this->_db->quoteIdentifier('colOne');
+        $colTwo  = $this->_db->quoteIdentifier('colTwo');
+        
+        $s = $this->_db->select()->from('A')->joinUsing('B', array($colOne,$colTwo));
+        $this->assertContains(
+            "JOIN {$table_B} ON {$table_B}.{$colOne} = {$table_A}.{$colOne}"
+            . " AND {$table_B}.{$colTwo} = {$table_A}.{$colTwo}",
+            $s->assemble()
+        );
+    }
+
+    /**
      * @group ZF-3309
      */
     public function testJoinUsingUsesTableNameOfTableBeingJoinedWhenAliasNotDefined()