2012-04-03 47 views
1

這是學說碼在ZF應用:主義innerjoin

$rowset = Doctrine_Query::create() 
    ->select("cu.clientuser, cu.usertitle, u.firstname") 
    ->from('Model_Db_Tblclientuser cu') 
    ->innerJoin('cu.Tblusers u') 
    ->whereIn('cu.clientid', (int)$clientid) 
    ->execute(); 


foreach ($rowset as $row) {    
    $list[] = array(
     'title' => $row->usertitle, 
     'firstname' => $row->firstname 
    ); 
} 

一個已經生成的查詢是這樣的一個:

SELECT 
    t.clientuser AS t__clientuser, 
    t.usertitle AS t__usertitle, 
    t2.userid AS t2__userid, 
    t2.firstname AS t2__firstname 
FROM 
    tblclientuser t INNER JOIN tblusers t2 ON t.userid = t2.userid 
WHERE 
    (t.clientid IN (1)) 

複製粘貼到phpMyAdmin的,它給出了一個完美結果。 但是當我運行ZF應用程序時,它出錯...

對於「clientuser」字段,一切正常。 但對於外地「名字」這是走錯了......

Unknown record property/related component "firstname" 
on "Model_Db_Tblclientuser" 

我該怎麼辦錯了嗎?

很奇怪的一點需要注意:如果我做

foreach ($rowset as $row) {    
    var_dump($row); 
} 

它與其他總表輸出的東西爲好,表並不在所有問題......

回答

0

我認爲誰我跑進同樣的問題,並通過選擇連接上的ID來解決它。

嘗試增加..

->select("cu.clientuser, cu.usertitle, u.id, u.firstname") 

或任何加盟關鍵是看是否能解決它。

+0

nope ..沒有幫助我。無論如何,Thx! – Aerypton 2012-04-03 18:45:33

0

您是否嘗試過執行大量選擇而不是自定義選擇?

->select("cu.*, u.*") 

或者也許刪除選擇。我知道這不是一個解決方案,並且(從symfony中的一個學說用戶),你的代碼中的每一件事都看起來很好。你使用1.2.4嗎?

PS:「救你的瀏覽器,不的var_dump學說1.x的對象」 :)

+0

我已經嘗試了所有... – Aerypton 2012-04-04 10:35:27

0

我意識到這是一個老問題,但如果有人運行到這個問題,我認爲,這是關係到我經歷過類似的事情。

請看這裏的解決方案:Doctrine Query Builder Bug?