2010-06-09 55 views
0

我已閱讀本如何在Doctrine Doctrine_RawSql查詢中刪除特定的dql部分?

Doctrine: How to remove part of a where clause from select query inside listener (preDqlSelect)?

但是,我仍然無法看到如何去除特定部分,這種不明確寫入,可有人給我解釋一下怎麼樣?

我Doctrine_RawSql

$a = new Doctrine_RawSql(); 

      $a->select('{m.username}, {m.age}, {m.photo_principale_petit_format},{m.photo_principale_grand_format}')->    
       from('(SELECT * FROM member_user where id > (SELECT max(id)-15000 as maximum FROM member_user)) as m')-> 
       innerJoin('member_group_history as g ON m.id = g.member_user_id')-> 
       where('g.old_member_group_id = ?', 7)-> 
       andWhere('m.is_visible = ?', 1)->    
       andWhere('m.sexe = ?', $this->getSexeRecherche())->    
       andWhere('m.age >= ?', $this->getMinAgeSearch())-> 
       andWhere('m.age <= ?', $this->getMaxAgeSearch())->  
       andWhereIn('m.member_group_id', array(10,11))-> 
       andWhere('g.created_at >= ?', date("Y-m-d H:i:s",strtotime("- 20 weeks")))-> 
       andWhere('g.created_at <= ?', date("Y-m-d H:i:s",strtotime("now")))-> 
       limit($limit)->    
       addComponent('m', 'MemberUser m');       
其實我只是想,如果我的查詢次數,收益足夠結果進行測試,如果不刪除特定謂詞

的樣本。

回答

0

$ a是一個對象,因此您可以使用「;」關閉正在構建的查詢。任何地方,你基於其他值一樣,並添加條件語句:

$a->select('t.something') 
->from('Table t') 
->where('t.id = 1'); 
if($todays_weather == 'sunny') $a->andWhere(t.weather = ?, 'sunny'); 
if($todays_temperature == 'hot') $a->andWhere(t.temperature = ?, 'hot'); 
etc... 

但是,如果你正在尋找建立一個計數的基礎上查詢,並要在單個查詢來實現這個,而不是打破它的分成兩部分,我想我會把它寫成直接的SQL來使事情變得簡單和清晰。在DQL消除GROUPBY的

+0

好啊好啊,但我想知道如何刪除謂語; d – belaz 2010-06-10 10:14:58

+0

我的觀點是,而不是刪除謂詞,你可以只讓他們從一開始條件-走。 – Tom 2010-06-10 10:44:25

3

例子:

$a->resetDQLPart('groupBy')