Index: library/Zend/Db/Select.php =================================================================== --- library/Zend/Db/Select.php (revision 24511) +++ library/Zend/Db/Select.php (working copy) @@ -896,7 +896,8 @@ private function _uniqueCorrelation($name) { if (is_array($name)) { - $c = end($name); + $k = key($name); + $c = is_string($k) ? $k : end($name); } else { // Extract just the last name of a qualified table name $dot = strrpos($name,'.'); Index: tests/Zend/Db/Select/TestCommon.php =================================================================== --- tests/Zend/Db/Select/TestCommon.php (revision 24511) +++ tests/Zend/Db/Select/TestCommon.php (working copy) @@ -1711,4 +1711,32 @@ $this->assertContains("JOIN {$table_B} ON {$table_B}.{$colname} = {$table_A}.{$colname}", $s->assemble()); } + /** + * @group ZF-3309 + */ + public function testJoinUsingUsesTableNameOfTableBeingJoinedWhenAliasNotDefined() + { + $table1 = $this->_db->quoteTableAs('table1'); + $table2 = $this->_db->quoteTableAs('table2'); + $colname = $this->_db->quoteIdentifier('column1'); + + $select = $this->_db->select(); + $select->from('table1')->joinUsing('table2', $colname); + $this->assertRegexp("/ON {$table2}.{$colname}/s", $select->assemble()); + } + + /** + * @group ZF-3309 + */ + public function testJoinUsingUsesAliasOfTableBeingJoinedWhenAliasIsDefined() + { + $table1 = $this->_db->quoteTableAs('table1'); + $table2_alias = $this->_db->quoteTableAs('t2'); + $colname = $this->_db->quoteIdentifier('column1'); + + $select = $this->_db->select(); + $select->from('table1')->joinUsing(array('t2'=>'table2'), $colname); + $this->assertRegexp("/ON {$table2_alias}.{$colname}/s", $select->assemble()); + } + }