views:

139

answers:

1

i have read this

http://stackoverflow.com/questions/1567652/doctrine-how-to-remove-part-of-a-where-clause-from-select-query-inside-listener

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 .

A: 

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.

Tom
ok good, but i want to know how to remove predicate ;D
belaz
My point is that instead of removing predicates, you could just make them conditional from the get-go.
Tom