views:

88

answers:

2

I am using Zend_Db_Select currently to retrieve hierarchical data from several joined tables. I need to be able to convert this easily into an array. Short of using a switch statement and listing out all the columns individually in order to sort the data, my thought was that if I could get the table names auto-prepended to the keys in the result array, that would solve my problem. So considering the following (assembled) SQL:

SELECT user.*, contact.* FROM user INNER JOIN contact ON contact.user_id = user.user_id

I would normally get a result array like this:

[username] => 'bob',
[contact_id] => 5,
[user_id] => 2,
[firstname] => 'bob',
[lastname] => 'larsen'

But instead I want this:

[user.user_id] => 2,
[user.username] => 'bob',
[contact.contact_id] => 5,
[contact.firstname] => 'bob',
[contact.lastname] => 'larsen'

Does anyone have an idea how to achieve this?

Thanks!

+1  A: 

Autoprepending without extending parts of ZF are AFAIK is not possible. You can, however tell it how to name the columns in the fetched rowset:

$select->from(array('users'=>$this->_name),
    array('user_id' => 'id', 'user_name' => 'username'));

and so on...

robertbasic
+1  A: 

As robertbasic eludes to, you'll need to extend your Row & RowSet classes to accomplish this. Take a look here to get started http://framework.zend.com/manual/en/zend.db.table.rowset.html

Matt S