2013-07-01 50 views
0

我有這樣的查詢:學說1個從一個表選擇與2別名

SELECT * FROM table a, table b 
WHERE a.col1=b.col1 
AND a.col2= b.col2 
AND a.col3= b.col3 
AND a.col4 = b.col4 
AND a.id <> b.id 

,搜索重複在表中。 我需要通過Doctrine 1查詢這個,但得到錯誤。這裏是我的代碼:

$q = Doctrine_Query::create() 
    ->from('table a, table b') 
    ->where('a.col1= b.col1') 
    ->andWhere('a.col2= b.col2') 
    ->andWhere('a.col3= b.col3') 
    ->andWhere('a.col4= b.col4') 
    ->andWhere('a.id <> b.id'); 

和錯誤是:

"Table" with an alias of "b" in your query does not reference the parent component it is related to. 

什麼是應該做的方式,我需要什麼?

+1

請再次查看['Documentation'](http://docs.doctrine-project.org/zh/2.1/reference/dql-doctrine-query-language.html)。 – alwaysLearn

+0

感謝您的回覆,但我使用Doctrine 1,並閱讀文檔,但沒有找到我的問題的答案。 – GoldenTabby

回答

0

的問題是,有表沒有關係,我添加它的schema.yml到我的實體:

relations: 
    SomeTable: 
     class: SomeTable 

所以它的工作原理。