开发者

Changing Zend_Db_Select's output to Zend_Db_Table_Rowset

开发者 https://www.devze.com 2023-01-04 07:47 出处:网络
I have the following code inside a class that extends Zend_Db_Table_Abstract: public function fetchByFriends($id) {

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.use开发者_StackOverflow社区r_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?


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消