Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework Select Objects And UNION()

I'm pretty sure this is not possible in Zend Framework (I have searched the Web, the documentation and issue tracker) but I just want to make sure so I'm asking here.

$select = $this->select();
$select->union($select1, $select2);

That doesn't work of course. To explain what I need. I need to use UNION() to merge 2 tables in a SELECT query, I know I could just do:

$select = "$select1 UNION $select2";

The problem is that would return a string and I need to get a select object so I can use it with Zend_Paginator.

I have already solved the issue by modifying my database architecture but I'm just curious if there is some workaround for this.

like image 296
Richard Knop Avatar asked Nov 28 '22 10:11

Richard Knop


1 Answers

Here's what I've done to make a union:

$select = $this->select();
//common select from both sides of the union goes here

$select1 = clone($select);
//select1 specifics here

$select2 = clone($select);
//select 2 specifics here

$db = $this->getAdapter();
$pageselect = $db->select()->union(array("($select1)", "($select2)"));

Remember Db_Select's __toString will print out the SQL generated by that select, to help you debug.

like image 164
Justin Avatar answered Dec 04 '22 08:12

Justin