Harish Kurup
Harish Kurup

Reputation: 7525

Binary OR not working in Symfony Propel Criteria

I am using Symfony 1.4 and Propel(ORM), i want to execute SQL query (SELECT * FROM 'myblog' WHERE 'blog_title' LIKE '%symfony%' OR 'blog_post' LIKE '%symfony%') want to get all the records from myblog which contains the word symfony. I wrote the Symfony code as,

$c = new Criteria();
$c->add(MyblogPeer::BLOG_TITLE, "%symfony%", Criteria::LIKE);
$c->addOr(MyblogPeer::BLOG_POST, "%symfony%", Criteria::LIKE);
$my_blog = MyblogPeer::doSelect($c);

but it returns a empty set. Is there any thing wrong in giving the parameter.

Upvotes: 2

Views: 1914

Answers (1)

guiman
guiman

Reputation: 1334

I think that in order to create an OR in the where closure, you need to create a Criterion and then add that criterion to the query, it should be something like this:

$c = new Criteria();
$criterion = $c->getNewCriterion(MyblogPeer::BLOG_TITLE, "%symfony%", Criteria::LIKE);
$criterion->addOr($c->getNewCriterion(MyblogPeer::BLOG_POST, "%symfony%", Criteria::LIKE));
$c->add($criterion);
$my_blog = MyblogPeer::doSelect($c);

Upvotes: 3

Related Questions