<?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>The Nerdiest Place on Earth &#187; symfony</title>
	<atom:link href="http://jasonswett.net/category/software-development/symfony/feed/" rel="self" type="application/rss+xml" />
	<link>http://jasonswett.net</link>
	<description>A Blog About Software Development, Databases, And Stuff That Doesn&#039;t Have To Do With Computers</description>
	<lastBuildDate>Fri, 03 Sep 2010 19:42:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Transactions with Doctrine</title>
		<link>http://jasonswett.net/transactions-with-doctrine/</link>
		<comments>http://jasonswett.net/transactions-with-doctrine/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 15:28:32 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://jasonswett.net/?p=943</guid>
		<description><![CDATA[If you&#8217;re going to make multiple related updates to your database, you should use a transaction. Unfortunately Doctrine&#8217;s documentation on transactions, like most of the Doctrine documentation I&#8217;ve seen, kind of sucks. Maybe their whole &#8220;Unit of Work&#8221; class without error handling makes sense somehow but I don&#8217;t get it. Here&#8217;s what they have:

&#60;?php
$conn = [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re going to make multiple related updates to your database, <a href="/why-you-should-use-database-transactions/">you should use a transaction</a>. Unfortunately <a href="http://www.doctrine-project.org/projects/orm/1.2/docs/cookbook/creating-a-unit-of-work-using-doctrine/en">Doctrine&#8217;s documentation on transactions</a>, like most of the Doctrine documentation I&#8217;ve seen, kind of sucks. Maybe their whole &#8220;Unit of Work&#8221; class without error handling makes sense somehow but I don&#8217;t get it. Here&#8217;s what they have:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$conn</span> <span style="color: #339933;">=</span> Doctrine_Manager<span style="color: #339933;">::</span><span style="color: #004000;">connection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
try <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">beginTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">performCreatesOrUpdates</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">performDeletes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$conn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">commit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> catch<span style="color: #009900;">&#40;</span>Doctrine_Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rollback</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is the right idea but it has the unforgivable flaw that it fails silently. If your transaction rolls back instead of commits, you won&#8217;t necessarily know about it. That&#8217;s bad. Here&#8217;s what I would have put:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$conn</span> <span style="color: #339933;">=</span> Doctrine_Manager<span style="color: #339933;">::</span><span style="color: #004000;">connection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
try
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">beginTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$myObject</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$myOtherObject</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">commit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rollback</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The code is mostly the same but that one crucial change&mdash;throwing an exception&mdash;makes a world of difference.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonswett.net/transactions-with-doctrine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to validate and sanitize a URL in symfony</title>
		<link>http://jasonswett.net/how-to-validate-and-sanitize-a-url-in-symfony/</link>
		<comments>http://jasonswett.net/how-to-validate-and-sanitize-a-url-in-symfony/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 14:41:57 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://jasonswett.net/?p=938</guid>
		<description><![CDATA[This validator works for symfony 1.4 and is not necessarily backward compatible.
If you&#8217;d like to both validate and sanitize a URL in symfony, it&#8217;s pretty easy. First, put the following code in lib/myValidatorUrl.class.php:

&#60;?php
&#160;
/**
 * myValidatorUrl validates and sanitizes a URL.
 *
 * @author Jason Swett (http://jasonswett.net/how-to-validate-and-sanitize-a-url-in-symfony)
 */
class myValidatorUrl extends sfValidatorUrl
&#123;
  protected function doClean&#40;$value&#41;
  [...]]]></description>
			<content:encoded><![CDATA[<p>This validator works for symfony 1.4 and is not necessarily backward compatible.</p>
<p>If you&#8217;d like to both validate and sanitize a URL in symfony, it&#8217;s pretty easy. First, put the following code in <code>lib/myValidatorUrl.class.php</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * myValidatorUrl validates and sanitizes a URL.
 *
 * @author Jason Swett (http://jasonswett.net/how-to-validate-and-sanitize-a-url-in-symfony)
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> myValidatorUrl <span style="color: #000000; font-weight: bold;">extends</span> sfValidatorUrl
<span style="color: #009900;">&#123;</span>
  protected <span style="color: #000000; font-weight: bold;">function</span> doClean<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$clean</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// If the URL doesn't start with &quot;http&quot;, add &quot;http://&quot;.</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$clean</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'http'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$clean</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://'</span><span style="color: #339933;">.</span><span style="color: #000088;">$clean</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Add a trailing slash if the URL doesn't have one.</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$clean</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$clean</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// If the URL still isn't valid after that, it probably wasn't close enough to begin with.</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateRegex</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$clean</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      throw <span style="color: #000000; font-weight: bold;">new</span> sfValidatorError<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'invalid'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$clean</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then, in the form where you have your URL field, add the following line to your <code>configure()</code> method:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> myValidatorPhone<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That&#8217;s all! Now, if someone enters a URL like &#8220;example.com&#8221;, it will get saved as &#8220;http://example.com/&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonswett.net/how-to-validate-and-sanitize-a-url-in-symfony/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to validate and sanitize a phone number in symfony</title>
		<link>http://jasonswett.net/how-to-validate-and-sanitize-a-phone-number-in-symfony/</link>
		<comments>http://jasonswett.net/how-to-validate-and-sanitize-a-phone-number-in-symfony/#comments</comments>
		<pubDate>Mon, 31 May 2010 18:59:03 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://jasonswett.net/?p=875</guid>
		<description><![CDATA[This validator works for symfony 1.4 and is not necessarily backward compatible.
If you&#8217;d like to both validate and sanitize a phone number in symfony, it&#8217;s pretty easy. First, put the following code in lib/sfValidatorPhone.class.php:

&#60;?php
&#160;
/**
 * sfValidatorPhone validates a phone number.
 *
 * @author Jason Swett (http://jasonswett.net/how-to-validate-a-phone-number-in-symfony)
 */
class sfValidatorPhone extends sfValidatorBase
&#123;
  protected function doClean&#40;$value&#41;
  [...]]]></description>
			<content:encoded><![CDATA[<p>This validator works for symfony 1.4 and is not necessarily backward compatible.</p>
<p>If you&#8217;d like to both validate and sanitize a phone number in symfony, it&#8217;s pretty easy. First, put the following code in <code>lib/sfValidatorPhone.class.php</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * sfValidatorPhone validates a phone number.
 *
 * @author Jason Swett (http://jasonswett.net/how-to-validate-a-phone-number-in-symfony)
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> sfValidatorPhone <span style="color: #000000; font-weight: bold;">extends</span> sfValidatorBase
<span style="color: #009900;">&#123;</span>
  protected <span style="color: #000000; font-weight: bold;">function</span> doClean<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$clean</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$phone_number_pattern</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/^(^(1\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{3})\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT])\.?\s*(\d+))*$)*$/'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// If the value isn't a phone number, throw an error.</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$phone_number_pattern</span><span style="color: #339933;">,</span> <span style="color: #000088;">$clean</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      throw <span style="color: #000000; font-weight: bold;">new</span> sfValidatorError<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'invalid'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Take out anything that's not a number.</span>
    <span style="color: #000088;">$clean</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/[^0-9]/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$clean</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Split the phone number into its three parts.</span>
    <span style="color: #000088;">$first_part</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$clean</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$second_part</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$clean</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$third_part</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$clean</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Format the phone number.</span>
    <span style="color: #000088;">$clean</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'('</span><span style="color: #339933;">.</span><span style="color: #000088;">$first_part</span><span style="color: #339933;">.</span><span style="color: #0000ff;">') '</span><span style="color: #339933;">.</span><span style="color: #000088;">$second_part</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$third_part</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$clean</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then, in the form where you have your phone number field, add the following line to your <code>configure()</code> method:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'phone'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorPhone<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That&#8217;s all! Now, if someone enters a number like 123.456.7890, it will get saved as (123) 456-7890.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonswett.net/how-to-validate-and-sanitize-a-phone-number-in-symfony/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing your title in symfony</title>
		<link>http://jasonswett.net/changing-your-title-in-symfony/</link>
		<comments>http://jasonswett.net/changing-your-title-in-symfony/#comments</comments>
		<pubDate>Fri, 28 May 2010 21:42:09 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://jasonswett.net/?p=834</guid>
		<description><![CDATA[The following is for symfony 1.4 and is not necessarily backward compatible.
If you just want to completely change your title in symfony and you&#8217;re okay with wiping out whatever&#8217;s already there, it&#8217;s simple. Just use this in your action:

$this-&#62;getResponse&#40;&#41;-&#62;setTitle&#40;'My New Title'&#41;;

But what if you want to keep the first part of your app&#8217;s title and [...]]]></description>
			<content:encoded><![CDATA[<p>The following is for symfony 1.4 and is not necessarily backward compatible.</p>
<p>If you just want to completely change your title in symfony and you&#8217;re okay with wiping out whatever&#8217;s already there, it&#8217;s simple. Just use this in your action:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'My New Title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>But what if you want to keep the first part of your app&#8217;s title and only change the rest? That&#8217;s also pretty easy. In <code>apps/frontend/templates/layout.php</code>, just change this</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> include_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>to this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;title&gt;The Static Part of Your Title <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$sf_response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTitle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;</pre></div></div>

<p>Now when you do this in your action</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'My New Title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The &#8220;The Static Part of Your Title&#8221; will still be there and only the rest of it will have changed.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonswett.net/changing-your-title-in-symfony/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inheritance with symfony and Doctrine ORM</title>
		<link>http://jasonswett.net/inheritance-with-symfony-and-doctrine-orm/</link>
		<comments>http://jasonswett.net/inheritance-with-symfony-and-doctrine-orm/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 19:02:51 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://jasonswett.net/blog/?p=263</guid>
		<description><![CDATA[The Problem
Doctrine ORM claims to support some kind of inheritance but I have yet to see a good example. The inheritance documentation on the Doctrine ORM site could be worse but it certainly has a lot of room for improvement. How about an example with some actual data? The symfony documentation for Doctrine inheritance lays [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The Problem</strong></p>
<p>Doctrine ORM claims to support some kind of inheritance but I have yet to see a good example. The <a href="http://www.doctrine-project.org/documentation/manual/1_2/en/inheritance">inheritance documentation on the Doctrine ORM site</a> could be worse but it certainly has a lot of room for improvement. How about an example with some actual data? The <a href="http://www.symfony-project.org/doctrine/1_2/en/04-Schema-Files#chapter_04_inheritance">symfony documentation for Doctrine inheritance</a> lays things out a little more clearly than the Doctrine docs but it still wants for good examples.</p>
<p><strong>The Solution</strong></p>
<p>Here I intend to perform a hearty exploration of Doctrine inheritance with the hope that I can show, by example, what it can and can&#8217;t do. The inheritance model I will use will be simple: the base class will be called <code>FarmAnimal</code> and the three inheriting classes will be <code>Cow</code>, <code>Dog</code> and <code>Chicken</code>. All <code>FarmAnimal</code>s will have at least a name, a sound and a number of legs. Each type of <code>FarmAnimal</code> will have the following unique properties: <code>Cow</code> will have a use (beef or dairy), a <code>Dog</code> will have a breed and a <code>Chicken</code> will have an egg color.</p>
<p>If you&#8217;d like to follow along, I&#8217;ve put together some <a href="/inheritance-with-symfony-and-doctrine-orm-project-setup/">setup instructions for this project</a>.</p>
<p>Doctrine offers three styles of inheritance: <em>Simple</em>, <em>Concrete</em> and <em>Column Aggregation</em>. The symfony docs give the following definitions:</p>
<table cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Concrete</td>
<td>Each child class has a separate table has all the columns of its parents</td>
</tr>
<tr>
<td>Simple</td>
<td>Each child class shares the same table and columns as its parents</td>
</tr>
<tr>
<td>Column Aggregation</td>
<td>All columns must be defined in the parent and each child class is determined by a <code>type</code> column</td>
</tr>
</tbody>
</table>
<p><strong>Simple Inheritance</strong></p>
<p>The Doctrine documentation shows an example where we have a <code>User</code> class and a <code>Group</code> class. Both of these classes inherit from <code>Entity</code> and neither one has any unique properties. When the example schema is evaluated, Doctrine only spits out one table: <code>entity</code>. If that&#8217;s all that &#8220;simple inheritance&#8221; is good for, I don&#8217;t really see how that&#8217;s inheritance. Any object you might instantiate, whether it be a <code>User</code>, <code>Group</code> or plain <code>Entity</code>, is an <code>Entity</code>, nothing more and nothing less. What&#8217;s gained there?</p>
<p>Let&#8217;s try something similar to their example but go a little further with it.</p>
<p><code>config/doctrine/schema.yml</code></p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">FarmAnimal:
  columns:
    name: string(20)
    sound: string(20)
    leg_count: integer
    created_at: timestamp
    updated_at: timestamp
&nbsp;
Cow:
  inheritance:
    extends: FarmAnimal
    type: simple
  columns:
    purpose:
      type: enum
      values: [beef, dairy]
&nbsp;
Dog:
  inheritance:
    extends: FarmAnimal
    type: simple
  columns:
    breed: string(20)
&nbsp;
Chicken:
  inheritance:
    extends: FarmAnimal
    type: simple
  columns:
    egg_color:
      type: enum
      values: [brown, white]</pre></div></div>

<p>Since we&#8217;re using enums, we&#8217;ll have to update <code>config/databases.yml</code> and add the <code>use_native_enum</code> directive:</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">all:
  doctrine:
    class: sfDoctrineDatabase
    param:
      dsn: 'mysql:host=localhost;dbname=inheritance'
      username: inheritance
      password: pass123
      attributes:
        use_native_enum: true</pre></div></div>

<p>Now let&#8217;s build the model, build the SQL and insert the SQL:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ symfony doctrine:build-model
$ symfony doctrine:build-sql
$ symfony doctrine:insert-sql</pre></div></div>

<p>What does this give us in the database?</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">TABLES</span>;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-----------------------+</span>
<span style="color: #66cc66;">|</span> Tables_in_inheritance <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-----------------------+</span>
<span style="color: #66cc66;">|</span> farm_animal           <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-----------------------+</span>
<span style="color: #cc66cc;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">DESCRIBE</span> farm_animal;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-----------------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">FIELD</span>      <span style="color: #66cc66;">|</span> Type                  <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #66cc66;">|</span> Extra          <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-----------------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> id         <span style="color: #66cc66;">|</span> bigint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>            <span style="color: #66cc66;">|</span> NO   <span style="color: #66cc66;">|</span> PRI <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> name       <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>           <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> sound      <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>           <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> leg_count  <span style="color: #66cc66;">|</span> bigint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>            <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> created_at <span style="color: #66cc66;">|</span> datetime              <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> updated_at <span style="color: #66cc66;">|</span> datetime              <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> purpose    <span style="color: #66cc66;">|</span> enum<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'beef'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'dairy'</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> breed      <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>           <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> egg_color  <span style="color: #66cc66;">|</span> enum<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'brown'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'white'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-----------------------+------+-----+---------+----------------+</span>
<span style="color: #cc66cc;">9</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.01</span> sec<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>As you can clearly see, all the inheriting classes&#8217; properties have been rolled into one table along with the base class&#8217;s properties. This is exactly what the Doctrine doc tells us, but it doesn&#8217;t totally spell it out with an example.</p>
<p>The table above is a bad model, both from a purist and pragmatic perspective. A purist might say, &#8220;We have three distinctly different types of things but only one data structure! Are we expected to deduce, based on which values are <code>NULL</code> and which are not, which type of <code>FarmAnimal</code> we&#8217;re dealing with? What if we add the idea of a <code>Cat</code> with a breed? How do we tell it apart from a <code>Dog</code>?&#8221; And a pragmatist might say, &#8220;What if we have 20 different types of <code>FarmAnimal</code>s, each having 5 different properties? That&#8217;s at least 100 columns in the <code>FarmAnimal</code> table!&#8221; I would agree with both the pragmatist and the purist. Imagine looking at a table with 100 columns, most of the rows having <code>NULL</code> in most of the columns most of the time. That&#8217;s an extreme example, but the principle is the same on any scale.</p>
<p>If you look at the PHP classes created by symfony, they&#8217;re meaningless. Take a look at <code>lib/model/doctrine/base/BaseChicken.class.php</code>, for example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * BaseChicken
 *
 * This class has been auto-generated by the Doctrine ORM Framework
 *
 *
 * @package    INHERITANCE
 * @subpackage model
 * @author     Your name here
 * @version    SVN: $Id: Builder.php 6820 2009-11-30 17:27:49Z jwage $
 */</span>
abstract <span style="color: #000000; font-weight: bold;">class</span> BaseChicken <span style="color: #000000; font-weight: bold;">extends</span> FarmAnimal
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">setUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>There&#8217;s nothing unique to Chicken there. All the properties of all the <code>FarmAnimal</code>s are kept in <code>lib/model/doctrine/base/BaseFarmAnimal.class.php</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">abstract <span style="color: #000000; font-weight: bold;">class</span> BaseFarmAnimal <span style="color: #000000; font-weight: bold;">extends</span> sfDoctrineRecord
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setTableDefinition<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTableName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'farm_animal'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'20'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sound'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'20'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'leg_count'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'integer'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'integer'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'created_at'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'timestamp'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'timestamp'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'updated_at'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'timestamp'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'timestamp'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'purpose'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'enum'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'enum'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'values'</span> <span style="color: #339933;">=&gt;</span>
             <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
              <span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'beef'</span><span style="color: #339933;">,</span>
              <span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dairy'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'breed'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'20'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'egg_color'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'enum'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'enum'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'values'</span> <span style="color: #339933;">=&gt;</span>
             <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
              <span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'brown'</span><span style="color: #339933;">,</span>
              <span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'white'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">setUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I&#8217;ve seen enough of &#8220;simple inheritance&#8221; to know that I would never use it. Let&#8217;s see what &#8220;concrete inheritance&#8221; is all about.</p>
<p><strong>Concrete Inheritance</strong></p>
<p>Apparently all that&#8217;s needed to switch from simple inheritance to concrete inheritance is to replace all instances of type: simple with type: concrete:</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">FarmAnimal:
  columns:
    name: string(20)
    sound: string(20)
    leg_count: integer
    created_at: timestamp
    updated_at: timestamp
&nbsp;
Cow:
  inheritance:
    extends: FarmAnimal
    type: concrete
  columns:
    purpose:
      type: enum
      values: [beef, dairy]
&nbsp;
Dog:
  inheritance:
    extends: FarmAnimal
    type: concrete
  columns:
    breed: string(20)
&nbsp;
Chicken:
  inheritance:
    extends: FarmAnimal
    type: concrete
  columns:
    egg_color:
      type: enum
      values: [brown, white]</pre></div></div>

<p>Let&#8217;s run our symfony commands again:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ symfony doctrine:build-model
$ symfony doctrine:build-sql
$ symfony doctrine:insert-sql</pre></div></div>

<p>What&#8217;s in the database now?</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">TABLES</span>;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-----------------------+</span>
<span style="color: #66cc66;">|</span> Tables_in_inheritance <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-----------------------+</span>
<span style="color: #66cc66;">|</span> chicken               <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> cow                   <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> dog                   <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> farm_animal           <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-----------------------+</span>
<span style="color: #cc66cc;">4</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>That&#8217;s encouraging: each class has its own separate table.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">DESCRIBE</span> farm_animal;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">FIELD</span>      <span style="color: #66cc66;">|</span> Type        <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #66cc66;">|</span> Extra          <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> id         <span style="color: #66cc66;">|</span> bigint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">|</span> NO   <span style="color: #66cc66;">|</span> PRI <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> name       <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> sound      <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> leg_count  <span style="color: #66cc66;">|</span> bigint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> created_at <span style="color: #66cc66;">|</span> datetime    <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> updated_at <span style="color: #66cc66;">|</span> datetime    <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-------------+------+-----+---------+----------------+</span>
<span style="color: #cc66cc;">6</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">DESCRIBE</span> cow;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+----------------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">FIELD</span>      <span style="color: #66cc66;">|</span> Type                 <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #66cc66;">|</span> Extra          <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+----------------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> id         <span style="color: #66cc66;">|</span> bigint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>           <span style="color: #66cc66;">|</span> NO   <span style="color: #66cc66;">|</span> PRI <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> name       <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>          <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> sound      <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>          <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> leg_count  <span style="color: #66cc66;">|</span> bigint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>           <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> created_at <span style="color: #66cc66;">|</span> datetime             <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> updated_at <span style="color: #66cc66;">|</span> datetime             <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> purpose    <span style="color: #66cc66;">|</span> enum<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'beef'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'dairy'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+----------------------+------+-----+---------+----------------+</span>
<span style="color: #cc66cc;">7</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">DESCRIBE</span> dog;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">FIELD</span>      <span style="color: #66cc66;">|</span> Type        <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #66cc66;">|</span> Extra          <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> id         <span style="color: #66cc66;">|</span> bigint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">|</span> NO   <span style="color: #66cc66;">|</span> PRI <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> name       <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> sound      <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> leg_count  <span style="color: #66cc66;">|</span> bigint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> created_at <span style="color: #66cc66;">|</span> datetime    <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> updated_at <span style="color: #66cc66;">|</span> datetime    <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> breed      <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-------------+------+-----+---------+----------------+</span>
<span style="color: #cc66cc;">7</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.01</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">DESCRIBE</span> chicken;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-----------------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">FIELD</span>      <span style="color: #66cc66;">|</span> Type                  <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #66cc66;">|</span> Extra          <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-----------------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> id         <span style="color: #66cc66;">|</span> bigint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>            <span style="color: #66cc66;">|</span> NO   <span style="color: #66cc66;">|</span> PRI <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> name       <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>           <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> sound      <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>           <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> leg_count  <span style="color: #66cc66;">|</span> bigint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>            <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> created_at <span style="color: #66cc66;">|</span> datetime              <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> updated_at <span style="color: #66cc66;">|</span> datetime              <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> egg_color  <span style="color: #66cc66;">|</span> enum<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'brown'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'white'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-----------------------+------+-----+---------+----------------+</span>
<span style="color: #cc66cc;">7</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>That looks like what I want. Each entity is represented by a table that has a column for each of its properties, nothing more and nothing less. The only way this might be improved, in my opinion, is if we could tell Doctrine that <code>FarmAnimal</code> is an abstract class and we don&#8217;t want a table for it.</p>
<p>If we look at the symfony-generated classes, they look how we&#8217;d expect:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">abstract <span style="color: #000000; font-weight: bold;">class</span> BaseChicken <span style="color: #000000; font-weight: bold;">extends</span> FarmAnimal
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setTableDefinition<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">setTableDefinition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTableName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'chicken'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'egg_color'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'enum'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'enum'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'values'</span> <span style="color: #339933;">=&gt;</span>
             <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
              <span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'brown'</span><span style="color: #339933;">,</span>
              <span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'white'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">setUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">abstract <span style="color: #000000; font-weight: bold;">class</span> BaseFarmAnimal <span style="color: #000000; font-weight: bold;">extends</span> sfDoctrineRecord
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setTableDefinition<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTableName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'farm_animal'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'20'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sound'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'string'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'20'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'leg_count'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'integer'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'integer'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'created_at'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'timestamp'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'timestamp'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'updated_at'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'timestamp'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
             <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'timestamp'</span><span style="color: #339933;">,</span>
             <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>   
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">setUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Doctrine&#8217;s &#8220;concrete inheritance&#8221; looks pretty solid. Let&#8217;s take a look at the third and final style, &#8220;column aggregation.&#8221;</p>
<p><strong>Column Aggregation</strong></p>
<p>To be honest, I&#8217;m pretty baffled as to what this one is supposed to do for us. Hopefully this example will make things clearer.</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">FarmAnimal:
  columns:
    name: string(20)
    sound: string(20)
    leg_count: integer
    created_at: timestamp
    updated_at: timestamp
&nbsp;
Cow:
  inheritance:
    extends: FarmAnimal
    type: column_aggregation
    keyField: type
    keyValue: 1
  columns:
    purpose:
      type: enum
      values: [beef, dairy]
&nbsp;
Dog:
  inheritance:
    extends: FarmAnimal
    type: column_aggregation
    keyField: type
    keyValue: 2
  columns:
    breed: string(20)
&nbsp;
Chicken:
  inheritance:
    extends: FarmAnimal
    type: column_aggregation
    keyField: type
    keyValue: 3
  columns:
    egg_color:
      type: enum
      values: [brown, white]</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ symfony doctrine:build-model
$ symfony doctrine:build-sql
$ symfony doctrine:insert-sql</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">TABLES</span>;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-----------------------+</span>
<span style="color: #66cc66;">|</span> Tables_in_inheritance <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-----------------------+</span>
<span style="color: #66cc66;">|</span> farm_animal           <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-----------------------+</span>
<span style="color: #cc66cc;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.00</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">DESCRIBE</span> farm_animal;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-----------------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">FIELD</span>      <span style="color: #66cc66;">|</span> Type                  <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #66cc66;">|</span> Extra          <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-----------------------+------+-----+---------+----------------+</span>
<span style="color: #66cc66;">|</span> id         <span style="color: #66cc66;">|</span> bigint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>            <span style="color: #66cc66;">|</span> NO   <span style="color: #66cc66;">|</span> PRI <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> name       <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>           <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> sound      <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>           <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> leg_count  <span style="color: #66cc66;">|</span> bigint<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>            <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> created_at <span style="color: #66cc66;">|</span> datetime              <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> updated_at <span style="color: #66cc66;">|</span> datetime              <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> type       <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>          <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> purpose    <span style="color: #66cc66;">|</span> enum<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'beef'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'dairy'</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> breed      <span style="color: #66cc66;">|</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>           <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">|</span> egg_color  <span style="color: #66cc66;">|</span> enum<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'brown'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'white'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span> YES  <span style="color: #66cc66;">|</span>     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span>                <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+-----------------------+------+-----+---------+----------------+</span>
<span style="color: #cc66cc;">10</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.01</span> sec<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>One table again, just like simple inheritance. Since I already rejected this structure, I see no reason to continue with column aggregation.</p>
<p><strong>Conclusion</strong></p>
<p>In my opinion, Doctrine&#8217;s simple inheritance and column aggregation are invalid and concrete is the only way to go. I hope these examples cleared up some confusion for anyone who had as much trouble with these concepts as I did.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonswett.net/inheritance-with-symfony-and-doctrine-orm/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Inheritance with symfony and Doctrine ORM: Project Setup</title>
		<link>http://jasonswett.net/inheritance-with-symfony-and-doctrine-orm-project-setup/</link>
		<comments>http://jasonswett.net/inheritance-with-symfony-and-doctrine-orm-project-setup/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 18:50:29 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://jasonswett.net/blog/?p=266</guid>
		<description><![CDATA[This post goes along with another post, Inheritance with symfony and Doctrine ORM. If you&#8217;ve found yourself here, you might want to start there.
First, set up the symfony project:

$ mkdir inheritance
$ cd inheritance/
$ mkdir -p lib/vendor
$ cd lib/vendor/
$ wget http://www.symfony-project.org/get/symfony-1.4.1.zip
$ mv symfony-1.4.1 symfony
$ rm symfony
$ rm symfony-1.4.1.zip
$ cd ../../
$ php lib/vendor/symfony/data/bin/symfony -V
symfony version 1.4.1 (/var/www/inheritance/lib/vendor/symfony/lib)

$ [...]]]></description>
			<content:encoded><![CDATA[<p>This post goes along with another post, <a href="/inheritance-with-symfony-and-doctrine-orm/">Inheritance with symfony and Doctrine ORM</a>. If you&#8217;ve found yourself here, you might want to start there.</p>
<p>First, set up the symfony project:</p>
<pre>
$ mkdir inheritance
$ cd inheritance/
$ mkdir -p lib/vendor
$ cd lib/vendor/
$ wget http://www.symfony-project.org/get/symfony-1.4.1.zip
$ mv symfony-1.4.1 symfony
$ rm symfony
$ rm symfony-1.4.1.zip
$ cd ../../
$ php lib/vendor/symfony/data/bin/symfony -V
symfony version 1.4.1 (/var/www/inheritance/lib/vendor/symfony/lib)

$ php lib/vendor/symfony/data/bin/symfony generate:project INHERITANCE
</pre>
<p>Then create the database:</p>
<pre>
mysql&gt; create database inheritance;
Query OK, 1 row affected (0.06 sec)
</pre>
<p>Following the <a href="http://en.wikipedia.org/wiki/Principle_of_least_privilege">principle of least privilege</a>, create a user that only has access to the <code>inheritance</code> database and nothing else:</p>
<pre>
mysql&gt; create user 'inheritance'@'localhost' identified by 'pass123';
Query OK, 0 rows affected (0.24 sec)

mysql&gt; grant all on inheritance.* to 'inheritance'@'localhost';
Query OK, 0 rows affected (0.00 sec)
</pre>
<p>Now tell symfony about the database:</p>
<pre>
$ php symfony configure:database "mysql:host=localhost;dbname=inheritance" inheritance pass123
</pre>
<p>And create the frontend app:</p>
<pre>
$ symfony generate:app frontend
$ chmod 777 cache/ log/
</pre>
<p>In order for your stylesheets to work, you&#8217;ll have to add a directive to your Apache config file similar to the following. My project lives in /var/www/inheritance; yours might be different. (Don&#8217;t forget to restart Apache after you add this.)</p>
<pre>
Alias /inheritance/web/sf /var/www/inheritance/lib/vendor/symfony/data/web/sf
</pre>
<p>Lastly, you might need to modify web/frontend_dev.php. My dev server is not the same machine that I use to look at what I&#8217;m developing, so I can&#8217;t restrict access to 127.0.0.1. For this temporary little project, it&#8217;s safe enough for me just to allow access from anywhere.</p>
<pre>
// this check prevents access to debug front controllers that are deployed by accident to production servers.
// feel free to remove this, extend it or make something more sophisticated.
/*
if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')))
{
die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
*/

require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');

$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
sfContext::createInstance($configuration)-&gt;dispatch();
</pre>
<p>That&#8217;s all.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonswett.net/inheritance-with-symfony-and-doctrine-orm-project-setup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
