2013-06-12 36 views
0

在我的應用程序(與Symfony 1.4和Doctrine開發),我試圖讓所有用戶基於idempresa的用戶登錄。idempresa是在sf_guard_user_profile表中,這是模式爲:堅持試圖讓只有用戶idempresa

SfGuardUserProfile: 
    connection: doctrine 
    tableName: sf_guard_user_profile 
    columns: 
    id: { type: integer(8), primary: true } 
    user_id: { type: integer(8), primary: false } 
    idempresa: { type: integer(4), primary: false } 
    relations: 
    User: 
     local: user_id 
     class: sfGuardUser 
     type: one 
     foreignType: one 
     foreignAlias: SfGuardUserProfile 
     onDelete: CASCADE 
     onUpdate: CASCADE 

我試圖與此查詢:

Doctrine_Core::getTable('sfGuardUser') 
    ->createQuery('u') 
    ->leftJoin('u.Profile p') 
    ->where('idempresa = ?', $id_empresa) 
    ->execute(); 

但得到這個錯誤:

Unknown relation alias Profile

我的代碼有什麼問題?

回答

2

sfGuardUsersfGuardUserProfile之間的關係不叫Profile而是SfGuardUserProfile。所以,你應該在你的查詢生成器中使用:

->leftJoin('u.SfGuardUserProfile p') 
+0

我敢肯定,我嘗試但不工作,也許一個錯字,我累了凌晨2點,反正感謝 – Reynier

+0

這絕對是樂趣編寫代碼凌晨2點,但你很容易陷入這樣簡單的錯誤。 ;) –