开发者

How to remove specific dql part in a doctrine Doctrine_RawSql query?

i have read this

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

but, i still cant see how to remove specific part, this is not explicitly written, can some one explain me how ?

a sample of my 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');          开发者_运维技巧                

in fact i just want to test if my query count return enough result, and remove specific predicates if not .


Example of removing groupBy on DQL:

$a->resetDQLPart('groupBy')


The $a is an object so you can close the query you're building with a ";" anywhere you like and add conditional statements based on other values:

$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...

However, if you're looking to build the query on the basis of a count AND you want to achieve this in a single query instead of breaking it into two, I think I'd write it as direct SQL to make things easier and clearer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜