ZF2-221: Joins in Zend\Db\Sql\Select should allow providing aliased field names

Issue Type: Improvement Created: 2012-03-13T19:11:17.000+0000 Last Updated: 2012-05-11T21:06:32.000+0000 Status: Resolved Fix version(s): Reporter: Guillaume Métayer (willy0275) Assignee: Ralph Schindler (ralph) Tags: - Zend\Db

Related issues: Attachments:


The join() method in Zend\Db\Sql\Select.php doesn't allow passing an aliased field name in the $columns parameter. The array should allow passing the fields as an associative array, for example array('aliasedName' => 'fieldName') ... It's very important in complex joins where some field names are identical and clashing.


Posted by Martin Hujer (mhujer) on 2012-04-02T20:32:11.000+0000


<pre class="highlight">
--- a/tests/Zend/Db/Sql/SelectTest.php
+++ b/tests/Zend/Db/Sql/SelectTest.php
@@ -305,6 +305,11 @@ class SelectTest extends \PHPUnit_Framework_TestCase
         $select9 = new Select;
         $select9->from('foo')->join('zac', 'm = n', array('bar', 'baz'));
         $sql9 = 'SELECT "foo".*, "zac"."bar", "zac"."baz" FROM "foo" INNER JOIN "zac" ON "m" = "n"';
+        // join with column aliases
+        $select9a = new Select;
+        $select9a->from('foo')->join('zac', 'm = n', array('bar', 'bat' => 'baz'));
+        $sql9a = 'SELECT "foo".*, "zac"."bar", "zac"."baz" AS "bat" FROM "foo" INNER JOIN "zac" ON "m" = "n"';

Posted by Ralph Schindler (ralph) on 2012-05-11T19:59:53.000+0000

This is fixed in latest master, please try it.

Posted by Martin Hujer (mhujer) on 2012-05-11T21:06:32.000+0000

Works fine. Thanks.

Have you found an issue?

See the Overview section for more details.


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