Просмотр исходного кода

ZF-4440 - Fixed Zend_Db_Table_Select::union()

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18199 44c647ce-9c0f-0410-b52a-842ac1e357ba
beberlei 16 лет назад
Родитель
Сommit
f059d20fcf
2 измененных файлов с 28 добавлено и 14 удалено
  1. 18 14
      library/Zend/Db/Table/Select.php
  2. 10 0
      tests/Zend/Db/Table/Select/TestCommon.php

+ 18 - 14
library/Zend/Db/Table/Select.php

@@ -193,23 +193,27 @@ class Zend_Db_Table_Select extends Zend_Db_Select
         $primary = $this->_info[Zend_Db_Table_Abstract::NAME];
         $schema  = $this->_info[Zend_Db_Table_Abstract::SCHEMA];
 
-        // If no fields are specified we assume all fields from primary table
-        if (!count($fields)) {
-            $this->from($primary, self::SQL_WILDCARD, $schema);
-            $fields = $this->getPart(Zend_Db_Table_Select::COLUMNS);
-        }
 
-        $from = $this->getPart(Zend_Db_Table_Select::FROM);
+        if (count($this->_parts[self::UNION]) == 0) {
+            
+            // If no fields are specified we assume all fields from primary table
+            if (!count($fields)) {
+                $this->from($primary, self::SQL_WILDCARD, $schema);
+                $fields = $this->getPart(Zend_Db_Table_Select::COLUMNS);
+            }
+
+            $from = $this->getPart(Zend_Db_Table_Select::FROM);
 
-        if ($this->_integrityCheck !== false) {
-            foreach ($fields as $columnEntry) {
-                list($table, $column) = $columnEntry;
+            if ($this->_integrityCheck !== false) {
+                foreach ($fields as $columnEntry) {
+                    list($table, $column) = $columnEntry;
 
-                // Check each column to ensure it only references the primary table
-                if ($column) {
-                    if (!isset($from[$table]) || $from[$table]['tableName'] != $primary) {
-                        require_once 'Zend/Db/Table/Select/Exception.php';
-                        throw new Zend_Db_Table_Select_Exception('Select query cannot join with another table');
+                    // Check each column to ensure it only references the primary table
+                    if ($column) {
+                        if (!isset($from[$table]) || $from[$table]['tableName'] != $primary) {
+                            require_once 'Zend/Db/Table/Select/Exception.php';
+                            throw new Zend_Db_Table_Select_Exception('Select query cannot join with another table');
+                        }
                     }
                 }
             }

+ 10 - 0
tests/Zend/Db/Table/Select/TestCommon.php

@@ -253,6 +253,16 @@ abstract class Zend_Db_Table_Select_TestCommon extends Zend_Db_Select_TestCommon
         $this->assertContains('tableB', $select4Text);
     }
 
+    public function testAssembleDbTableUnionSelect()
+    {
+        $table = $this->_getSelectTable('accounts');
+        $select1 = $table->select();
+        $select2 = $table->select();
+
+        $selectUnion = $table->select()->union(array($select1, $select2));
+        $selectUnionSql = $selectUnion->assemble();
+    }
+
     // ZF-3239
 //    public function testFromPartIsAvailableRightAfterInstantiation()
 //    {