If you have a complex SQL query involving many joins (for example returning Articles with their associated many to many Tags) is there anything in Zend Framework that will produce the lovely CakePHP style database results:
Array
(
[0] => Array
(
[ModelName] => Array
(
[id] => 83
[field1] => value1
[field2] => value2
[field3] => value3
)
[AssociatedModelName] => Array
(
[id] => 1
[field1] => value1
[field2] => value2
[field3] => value3
)
)
)
I don't mind if it's an object rather than an array, I just wondered if by using Zend_Db_Table to build a SELECT JOIN query I could save some leg work and get some nicely formatted results.
Here is the kind of code I'm using to build the query:
$select = $db->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
$select->from('tableName','fieldName')
->join('joinTable', 'joinTable.keyId = tableName.keyId',array())
->where('tableName.userId = ?', $userId);
$resultSet = $db->fetchAll($select);
Nothing as pretty as what you're used to just the data I asked for. The normal Result would be a rowset object, however the ->toArray() is available for most *Zend_DbTable_Abstract* methods.
The $result->toArray() truncated and dumped using Zend_debug::dump():
Lead Tracks array(7) {
[0] => array(9) {
["trackid"] => string(2) "24"
["weekendid"] => string(1) "8"
["shiftid"] => string(1) "1"
["bidlocationid"] => string(1) "1"
["qty"] => string(1) "2"
["lead"] => string(1) "1"
["bidloc"] => string(14) "out of service"
["deptcode"] => string(3) "491"
["stationid"] => string(1) "1"
}
The query:
where = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
->setIntegrityCheck(FALSE);
$where->where('track.bidlocationid = ?', $bidlocationId)
->where('lead = ?', $lead)
->join('bidlocation', 'bidlocation.bidlocationid = track.bidlocationid')
->where('bidlocation.stationid = ?', $stationId)
->order('shiftid ASC')
->order('weekendid ASC');
$result = $this->fetchAll($where);
sorry, just utility :)