views:

16

answers:

1

I have the following code inside a class that extends Zend_Db_Table_Abstract:

public function fetchByFriends($id) {
    /*
     * SELECT * FROM list 
     * INNER JOIN friendship ON 
     * list.user_id = friendship.friend_id
     * WHERE friendship.user_id = ?
     */

    $select = $this->select()
                   ->from("list")
                   ->join("friendship", "list.user_id = friendship.friend_id")
                   ->where("friendship.user_id = ?", $id);
    $select->setIntegrityCheck(false); // allows joins within a DbTable

    $stmt = $select->query();
    return $this->fetchAll($stmt);
}

While the query works fine the data returned is of an array. Is there some way to refactor this so that fetchAll returns it as a Zend_Db_Table_Rowset, rather than an array?

A: 

Poor research on my part. I found the answer in Zend's reference manual:

Advanced usage

Example #27 Using a lookup table to refine the results of fetchAll()

$table = new Bugs();

// retrieve with from part set, important when joining
$select = $table->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
$select->setIntegrityCheck(false)
       ->where('bug_status = ?', 'NEW')
       ->join('accounts', 'accounts.account_name =

bugs.reported_by') ->where('accounts.account_name = ?', 'Bob');

$rows = $table->fetchAll($select);
Ross