2011-03-17 42 views
1

我有2表用戶並在用戶有很多user_comments USER_COMMENT,我放下映射爲
Zend的映射一對多使用fetchall

User 
$_dependentTables = array('User_Comments); 

User_Comments 
$_referenceMap = array(
    'User' => array(
    'columns' => 'id', 
    'refTableClass' => 'User', 
    'refColumns' => 'id' 
) 
);

有我的方式要做user-> fetchAll()並獲取user_comments而不做循環查詢(在cakephp中,它會對user_comments執行一個查詢,然後在(ids)中將其格式化爲一個數組,但我無法使用cake)。這可能在zend與我手動嗎?由於

回答

2

試試這個

$sql=$this->getAdapter()->select() 
         ->from("user_comment") 
         ->join("user", "user.id=user_comment.userid") 
         ->where("user_comment.id=?",$userId); 

$result=$this->getAdapter()->query($sql)->fetchAll(); 

這可能幫助ü....