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);
So, now you can perform your query using criteria OR in symfony.
Yes, no doubt it’s complicated but it works!
straight from the propel guide, to perform simple or comperrison
// Find all authors with last name of Tolstoy, Dostoevsky, or Bakhtin
$c2 = new Criteria();
$c2->add(AuthorPeer::LAST_NAME, array(“Tolstoy”, “Dostoevsky”, “Bakhtin”), Criteria::IN);
Thank you very much for giving clue for how to add more criteria with or and and. 🙂
It is very different than i thought. SQL people needs to bang owns head many time on wall to figure out how to use ORM based query.