This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Difference between addOr() and addAnd()

Discussion specific to symfony 1.1.x stable

Difference between addOr() and addAnd()

by kirankadam72 » Tue Feb 01, 2011 12:53 pm

Hello Friends,
I am using symfony 1.1.1 and propel is my ORM tool.
Can somebody tell me the difference between addOr() and addAnd().
And also i do not understand what exactly work of getNewCriterion()
Please reply me
Thanks In Advanced
Junior Member
Posts: 9
Joined: Tue Jan 18, 2011 3:42 pm

Re: Difference between addOr() and addAnd()

by Tirthesh » Tue Mar 15, 2011 7:11 am


Simply, 'addOr' is used in the same way as we use 'OR' in where clause in mysql statements. And "addAnd" is used in the same way as we use "AND" in where clause.

Code: Select all
$c = new Criteria();
$c1 = $c->getNewCriterion(BookPeer::TITLE, '%Leo%', Criteria::LIKE);
$c2 = $c->getNewCriterion(BookPeer::ISBN, '1234', Criteria::EQUAL);

As using Criteria we build the query in diff. statements, we define where condition for each field separately. In simple language, we can use the new criterian to form a part of the where clause and attach the same to the main clause using ADD or OR.

As shown in above example, a new condition for TITLE and ISBN are formed separately using new criterion and using 'OR' It's joining the query to form a statement like below :

$c1->addOr($c2) results :

(`TITLE` LIKE '%Leo%' OR ISBN == '1234')

and $c->add($c1) attaches the above condition to the main statement:

-----WHERE (`TITLE` LIKE '%Leo%' OR ISBN == '1234')-----

Code: Select all

Hope above explanation helps you understand the same. Have tried to explain in simple words(practically). Any expert can explain you more technically.

Symfony 1.4.8 + Propel 1.4.2
Posts: 78
Joined: Fri Nov 26, 2010 8:27 am