ZF-4440: UNION does not work with Zend_Db_Table_Select

Description

Trying to use a UNION with a Zend_Db_Table_Select fails because it tries to call joinInner when it assembles the query (to ensure data is being selected from the correct table), which results in an exception being thrown (because you can't join on a UNION).

A (somewhat bad, but workable) workaround is to do something like this:


--- Db/Table/Select.php (revision 7)
+++ Db/Table/Select.php (working copy)
@@ -150,6 +150,10 @@
      */
     public function from($name, $cols = self::SQL_WILDCARD, $schema = null)
     {
+        if (count($this->_parts[self::UNION])) {
+            return $this;
+        }
+
         if ($name instanceof Zend_Db_Table_Abstract) {
             $info = $name->info();
             $name = $info[Zend_Db_Table_Abstract::NAME];

Regards,

Comments

9 months on, this is still not fixed. I have been using the provided patch since this issue was first entered into the tracker and it has been working fine. I would recommend committing it, since it is very small and does not seemingly cause any side-effects even with many complex built queries.

Fixed in trunk and merged into 1.9 release branch.

I modified your patch a little to check for the union in the assemble() method, which seems to be a more appropriate location for me.