It seems to me that I should skip something very simple. This is a very simple task, all I want to do is get something like:
SELECT * FROM lookup_items JOIN lookup ON lookup_items.lookup_id = lookup.id
This returns all columns for all joined tables in plain SQL. Here is my attempt in zf2:
$select = new Select(); $select->from('lookup_items'); $select->join('lookup', 'lookup_items.lookup_id = lookup.id');
The result set includes only columns in 'lookup_items'. I tried various ways to get search columns, including:
$select->columns(array('lookup_items.*', 'lookup.*'));
But they all just explode. Of course, there is a way to do this, and itโs just that I donโt miss it completely.
I thought a simple example is to avoid confusion, but there is more code here:
class LookupItemsTable extends AbstractTableGateway { public function getList($resource) { $system_name = str_replace('*', '%', strtoupper($resource)); $joinTable = 'lookup'; $select = new Select(); $select->from($this->table); $select->join($joinTable, "{$this->table}.lookup_id = {$joinTable}.id"); $where = array(); $where[] = "{$this->table}.enabled is true"; $where[] = "{$joinTable}.enabled is true"; $where[] = "UPPER({$joinTable}.system_name) ilike '{$system_name}'"; $select->where($where); $sort[] = 'sort_order ASC'; $sort[] = 'value ASC'; $select->order($sort); $rowset = $this->selectWith($select); return $rowset; } }
Where:
$resource = $this->params()->fromRoute('resource', 'BUSINESS');
And $ this-> table - 'lookup_items'. In fact, all I want to do is get the columns from both joined tables. I assume that there is a zf2 way to just make a direct SQL query without any Oal-falderal, so I could just force it that way. But I would prefer to work within the framework as much as possible.
mutatron
source share