Issues

ZF-5953: Support joining with multiple columns with joinUsing

Issue Type: Improvement Created: 2009-03-05T21:14:51.000+0000 Last Updated: 2012-05-30T13:30:02.000+0000 Status: Resolved Fix version(s): - 1.12.0 (27/Aug/12)

Reporter: David Muir (dmuir) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Db_Select

  • FixForZF1.12

Related issues: Attachments:

Description

Currently, if you need to join on multiple columns, you cannot use joinUsing();

The join condition should accept an array of columns to join on.

SQL:

<pre class="highlight">
SELECT *
FROM table1
JOIN table2 USING (column1, column2)

Zend_Db_Select:

<pre class="highlight">
$select = $db->select()
  ->from('table1')
  ->joinUsing('table2', array('column1','column2'));

Originally suggested here: ZF-1845, but was only half implemented.

Comments

Posted by Adam Lundrigan (adamlundrigan) on 2012-05-12T01:37:06.000+0000

This issue still exists. Reproducing test case:

<pre class="highlight">
Index: tests/Zend/Db/Select/TestCommon.php
===================================================================
--- tests/Zend/Db/Select/TestCommon.php (revision 24794)
+++ tests/Zend/Db/Select/TestCommon.php (working copy)
@@ -1712,6 +1712,24 @@
     }
 
     /**
+     * @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()

Posted by Adam Lundrigan (adamlundrigan) on 2012-05-30T13:30:02.000+0000

Fixed in trunk r24833

Have you found an issue?

See the Overview section for more details.

Copyright

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

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

Contacts