ZF-4440: UNION does not work with Zend_Db_Table_Select

Issue Type: Bug Created: 2008-10-01T10:22:58.000+0000 Last Updated: 2009-09-17T14:27:17.000+0000 Status: Resolved Fix version(s): - 1.9.3 (22/Sep/09)

Reporter: C Snover (snover) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db_Table

Related issues: Attachments:


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:

<pre class="highlight">
--- 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];



Posted by C Snover (snover) on 2009-07-24T15:12:48.000+0000

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.

Posted by Benjamin Eberlei (beberlei) on 2009-09-17T14:26:43.000+0000

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.

Have you found an issue?

See the Overview section for more details.


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

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