<?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>woblog &#187; SQL</title>
	<atom:link href="http://www.whiteoctober.co.uk/blog/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.whiteoctober.co.uk/blog</link>
	<description>great stuff about the web</description>
	<lastBuildDate>Mon, 05 Dec 2011 16:53:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Don&#8217;t be afraid to NOT use the ORM&#8230;</title>
		<link>http://www.whiteoctober.co.uk/blog/2009/10/16/dont-be-afraid-to-not-use-the-or/</link>
		<comments>http://www.whiteoctober.co.uk/blog/2009/10/16/dont-be-afraid-to-not-use-the-or/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 15:06:03 +0000</pubDate>
		<dc:creator>Rich</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[Web technologies]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.whiteoctober.co.uk/blog/?p=353</guid>
		<description><![CDATA[I&#8217;ve been racking my brains the past couple of days with a Doctrine issue within a Symfony project. I was constructing a bank statement-esque page, which iterated over a &#8220;StatementEntry&#8221; table and displayed the results. Entries could either be of model Type A or model Type B, with the relevant model ID stored in the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been racking my brains the past couple of days with a <a title="Doctrine" href="http://www.doctrine-project.org/">Doctrine</a> issue within a <a title="Symfony" href="http://www.symfony-project.org/">Symfony</a> project.  I was constructing a bank statement-esque page, which iterated over a &#8220;StatementEntry&#8221; table and displayed the results.  Entries could either be of model Type A or model Type B, with the relevant model ID stored in the StatementEntry table.  The relationship was defined by a &#8220;type&#8221; column.  Type A and B models also had other relationships after the initial one.</p>
<p>The problem I discovered was that obviously Doctrine didn&#8217;t know what the conditional relationships were, since it was dependant on the type column.  I researched some different approaches:</p>
<ol>
<li> <strong>Doctrine&#8217;s RawSql</strong>
<p>This approach worked for generating the correct SQL query without a problem, but the issue then arose of how Doctrine could hydrate the result set.  Answer was &#8211; it couldn&#8217;t :-) Well, I lie &#8211; I could use Doctrine::HYDRATE_SCALAR but I had issues with other related models, where I was joining to a table twice but under different aliases, which failed, since the scalar hydration would override earlier joins on the same table.</li>
<li> <strong>Column aggregation</strong>
<p>Column aggregation looked great initially &#8211; I could have a &#8220;TypeAEntry&#8221; and a &#8220;TypeBEntry&#8221;, and Doctrine would have handled the typing of the Entry automatically.  I couldn&#8217;t however see a way to query &#8220;in reverse&#8221; &#8211; get all Entries and their associated models.</li>
<li> <strong>Write a raw SQL query, and use Doctrine&#8217;s PDO instance to retrieve the data.</strong></li>
</ol>
<p>Option 3) was the one I settled for in the end.  It meant of course that I had to specify column names, and perform all the joins myself, but it did mean I could specify precisely what data I wanted back.  This came back in the form of a normal array.  I&#8217;d tried to stay away from this option intially, but after spending too long researching the other 2 and hitting brick walls, I bit the bullet and dropped down to the raw stuff.  And hey presto!</p>
<p>Note &#8211; this approach will only work if you want the data to be read-only.  If you want to then use Doctrine&#8217;s model goodness, you&#8217;ll need to work out how to transform that *back* into a model.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.whiteoctober.co.uk/blog/2009/10/16/dont-be-afraid-to-not-use-the-or/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding propel objects</title>
		<link>http://www.whiteoctober.co.uk/blog/2008/04/15/finding-propel-objects/</link>
		<comments>http://www.whiteoctober.co.uk/blog/2008/04/15/finding-propel-objects/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 08:42:04 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[Web technologies]]></category>
		<category><![CDATA[Object-relational mapping]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.whiteoctober.co.uk/blog/?p=42</guid>
		<description><![CDATA[In the White October office we use a programing framework called Symfony for some of our projects. It provides us with well erm a framework to develop our web applications, it gives us a standard way of dealing with web requests, keeping our code in a standard set of folders and lots of handy tools [...]]]></description>
			<content:encoded><![CDATA[<p>In the White October office we use a programing framework called <a class="zem_slink" title="Symfony" rel="homepage" href="http://www.symfony-project.com/" target="_blank">Symfony</a> for some of our projects. It provides us with well erm a framework to develop our web applications, it gives us a standard way of dealing with web requests, keeping our code in a standard set of folders and lots of handy tools to speed up the development of applications.</p>
<p>One such tool is the <a class="zem_slink" title="Propel (PHP)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Propel_%28PHP%29" target="_blank">Propel</a> <a class="zem_slink" title="Object-relational mapping" rel="wikipedia" href="http://en.wikipedia.org/wiki/Object-relational_mapping" target="_blank">ORM</a> which gives us objects to represent the tables we have in databases, it reduces the amount of <a class="zem_slink" title="SQL" rel="wikipedia" href="http://en.wikipedia.org/wiki/SQL" target="_blank">SQL</a> you have to write in an application to almost nil.</p>
<p>Sometimes however searching for information in a table can be a lot harder in Propel that it would be in SQL, you have to use &#8220;Criteria&#8221; objects and they are not as intuitive as they should be.</p>
<p>However <a href="http://redotheweb.com/"> François Zaninotto</a>, one of the creators of the Symfony framework, has <a href="http://redotheweb.com/2008/04/10/propel-is-not-hard-anymore/">written a finder plugin</a> for Propel Objects called <a href="http://trac.symfony-project.com/wiki/sfPropelFinderPlugin">sfPropelFinderPlugin</a> which aims to make this process a lot easier and more intuitive.<br />
<code><br />
// With Peer and Criteria<br />
$c = new Criteria()<br />
$c-&gt;add(ArticlePeer::TITLE, '%world', Criteria::LIKE);<br />
$c-&gt;add(ArticlePeer::IS_PUBLISHED, true);<br />
$c-&gt;addAscendingOrderByColumn(ArticlePeer::CREATED_AT);<br />
$articles = ArticlePeer::doSelect($c);<br />
// with sfPropelFinder<br />
$articles = sfPropelFinder::from('Article')-&gt;whereTitle('like', '%world')-&gt;whereIsPublished(true)-&gt;orderByCreatedAt()-&gt;find();<br />
</code><br />
If you use Propel outside of Symfony you can also use this plugin as it is standalone.</p>
<p>I like the quote from the wiki page.<br />
<strong> &#8220;Think of sfPropelFinder as <a class="zem_slink" title="JQuery" rel="homepage" href="http://jquery.com/" target="_blank">jQuery</a> for Propel&#8221;</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.whiteoctober.co.uk/blog/2008/04/15/finding-propel-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

