Symfony: How to query using Criteria OR
I’m looking for way to do a simple query using criteria OR in symfony framework. The official documentation does not covers the sql query criteria for OR statement. After googling for while, there is some reference from the Propel Guide
To perform a simple SQL query with OR criteria is a bit complicated in symfony or i can say in Propel. Here’s the example of how to perform the SQL query for:
SELECT * FROM table_a WHERE (column_a = 1 OR column_a = 3) AND column_c = ‘xxx’
$c = new Criteria;
$c1 = $c->getNewCriterion(TableAPeer::COLUMN_A, 1);
$c2 = $c->getNewCriterion(TableAPeer::COLUMN_A, 2);
$c1->addOr($c2);
$c->add(TableAPeer::COLUMN_B, ‘xxx’);
$c->add($c1);
So, now you can perform your query using criteria OR in symfony.
Yes, no doubt it’s complicated but it works!
Posted at May 13th, 2008 by chua
If you think this article helps you to solve your problem and clear your headache, feel free to buy me a drink :)








