<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>devexp &#187; method</title>
	<atom:link href="http://www.devexp.eu/tag/method/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devexp.eu</link>
	<description>DEVelopment EXPerience, shared with the world!</description>
	<lastBuildDate>Tue, 16 Feb 2010 14:38:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Useful Propel criteria methods and constants</title>
		<link>http://www.devexp.eu/2009/04/06/useful-propel-criteria-methods-and-constants/</link>
		<comments>http://www.devexp.eu/2009/04/06/useful-propel-criteria-methods-and-constants/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 12:00:29 +0000</pubDate>
		<dc:creator>van Rumste Kenneth</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[criteria]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[query]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=551</guid>
		<description><![CDATA[I'm working with criteria quite often lately and must say it is a handy way of query writing. The only problem I have with criteria is that I don't seem to find a simple overview (list) of the most important methods you can add to it. I don't really like the Propel website as I [...]]]></description>
			<content:encoded><![CDATA[<p>I'm working with criteria quite often lately and must say it is a handy way of query writing. The only problem I have with criteria is that I don't seem to find a simple overview (list) of the most important methods you can add to it. I don't really like the <a href="http://propel.phpdb.org/trac/" target="_blank">Propel website</a> as I don't find the thing I need in a few seconds and that is a must for a lot of people. If I create a list of the most important criteria methods for myself, I rather share it with you guys...</p>
<p><strong>Simple Select query </strong>with 2 criteria to check:</p>
<pre class="brush: php;">
$c = new Criteria();
$c-&gt;add(AuthorPeer::FIRST_NAME, &quot;Karl&quot;);
$c-&gt;add(AuthorPeer::LAST_NAME, &quot;Marx&quot;, Criteria::NOT_EQUAL);
$authors = AuthorPeer::doSelect($c);
// $authors contains array of Author objects
</pre>
<p>In SQL this will be:</p>
<pre class="brush: php;">SELECT ... FROM author WHERE author.FIRST_NAME = 'Karl' AND author.LAST_NAME &lt;&gt; 'Marx';</pre>
<p>It's quite simple to write the criteria, the only thing needed to write them is a list of options.</p>
<p><span id="more-551"></span><strong>To add Or to the criteria</strong> that have to be checked write:</p>
<pre class="brush: php;">
$cton1 = $c-&gt;getNewCriterion(AuthorPeer::FIRST_NAME, 'Karl');
$cton2 = $c-&gt;getNewCriterion(AuthorPeer::LAST_NAME,  'Marx', Criteria:: NOT_EQUAL);

// combine them
$cton1-&gt;addOr($cton2);
</pre>
<p>In SQL this will be:</p>
<pre class="brush: php;">SELECT ... FROM author WHERE author.FIRST_NAME = 'Karl' OR author.LAST_NAME &lt;&gt; 'Marx';</pre>
<p>Quite simple isn't it, and the usage of criteria is quite readable once you start knowing all the options.</p>
<p>Possible operators for criteria (write them like Criteria::Equals)</p>
<ul type="disc">
<li>EQUAL (default)</li>
<li>NOT_EQUAL</li>
<li>GREATER_THAN</li>
<li>LESS_THAN</li>
<li>GREATER_EQUAL</li>
<li>LESS_EQUAL</li>
<li>LIKE</li>
<li>NOT_LIKE</li>
<li>IN</li>
<li>CUSTOM</li>
</ul>
<p>This allows you to write your own condition as second parameter.</p>
<ul type="disc">
<li>CUSTOM_EQUAL</li>
</ul>
<p>This is used to write a custom condition in an UPDATE query</p>
<ul type="disc">
<li>ISNULL</li>
<li>ISNOTNULL</li>
</ul>
<p>For some methods you need to add a line to the criteria to specify if they have to be used or not:</p>
<p><strong>$c-&gt;setIgnoreCase</strong>(true);<br />
This is to specify if the query should be case sensitive or not.</p>
<p><strong>$c-&gt;addJoin</strong>(ReviewPeer::BOOK_ID, BookPeer::ID, Criteria::INNER_JOIN);<br />
INNER JOIN (default) the table in parameter 1 to the table in parameter 2. In the same way you can RIGHT or LEFT JOIN.</p>
<p><strong>$c-&gt;addAscendingOrder</strong>ByColumn(table::column);<br />
This will add an ascending order for the specified column. Off course you can to the opposite too by using addDescendingOrderByColumn.</p>
<p><strong>$criteria-&gt;addSelectColumn</strong>(self::LABEL);<br />
This will add only this column to the select statement, by default he selects all fields of a table (default *)</p>
<p>All info about the methods and constants of criteria can be found <a href="http://propel.phpdb.org/docs/api/1.3/runtime/propel-util/Criteria.html" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/04/06/useful-propel-criteria-methods-and-constants/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
