<?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; Doctrine ORM</title>
	<atom:link href="http://jasonswett.net/category/software-development/databases/doctrine-orm/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>Wed, 08 Sep 2010 01:33:23 +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>jsDoctrineSchemaOverriderPlugin</title>
		<link>http://jasonswett.net/jsdoctrineschemaoverriderplugin/</link>
		<comments>http://jasonswett.net/jsdoctrineschemaoverriderplugin/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 01:25:24 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://jasonswett.net/?p=961</guid>
		<description><![CDATA[Why I Wrote This Plugin
In order to understand what this plugin is for, it&#8217;s helpful to have a little background. There are two ways to handle your schema in symfony:
Method 1: Write your config/doctrine/schema.yml by hand (for this post we&#8217;ll assume you&#8217;re using Doctrine) and run symfony doctrine:build-sql to generate your database tables. This is [...]]]></description>
			<content:encoded><![CDATA[<h3>Why I Wrote This Plugin</h3>
<p>In order to understand what this plugin is for, it&#8217;s helpful to have a little background. There are two ways to handle your schema in symfony:</p>
<p>Method 1: Write your <code>config/doctrine/schema.yml</code> by hand (for this post we&#8217;ll assume you&#8217;re using Doctrine) and run <code>symfony doctrine:build-sql</code> to generate your database tables. This is what most people do.</p>
<p>Method 2: Create your database tables by hand and run <code>symfony doctrine:build-schema</code> to generate your schema. This is what I do.</p>
<p>Why do I generate my schema from my database instead of generating my database from my schema? There&#8217;s one big reason. Every time you run <code>symfony doctrine:insert-sql</code>, your entire database—meaning now just the database structure, but the data as well—gets wiped out. The database <em>structure</em> is put right back in place but if you want to keep your <em>data</em> intact, you&#8217;re on your own. Doing a <code>mysqldump</code> only works for the most trivial changes. Because the symfony developers are well aware that you&#8217;re going to want your data to stay intact, they let you use what are called fixtures—sets of data that you can easily load into your database—but it seems terribly inefficient to have to manually shuffle around your fixture data each time you make a change to your database structure. Plus, what if you like to periodically load your production data into your development database so you&#8217;re working with a realistic dataset? As far as I know, fixtures don&#8217;t accommodate that. Those are the main reasons why I use <code>build-schema</code> instead of <code>build-sql</code>. (From now on, I will call these two methods the <em>build-from-database</em> method and the <em>build-from-schema</em> method.)</p>
<p>Neither the build-from-database method or the build-from-schema method is perfect. (I just find build-from-database &#8220;less bad.&#8221;) I&#8217;ve come across the following problems with build-from-database:</p>
<ul>
<li>If any of my entities inherit from other entities (read about that <a href="/inheritance-with-symfony-and-doctrine-orm/">here</a>), the relationship gets wiped out every time I build the schema</li>
<li>If I have SQL views in my database, each view shows up as a model, which doesn&#8217;t always make sense</li>
<li>If I have, say, a WordPress install as part of my website, all my WordPress tables show up as models (I know I could work around this by putting the WP install in a separate database. The point is that <em>every</em> table in your database will get translated into a model, regardless of whether you want them to or not</li>
</ul>
<p>These are the main problems I&#8217;ve had with the build-from-database method. The most frustrating part is that I would have to manually correct my schema <em>every single time</em> I ran <code>build-schema</code>! It gets old fast, as I&#8217;m sure you know if you do build-from-database instead of build-from-schema.</p>
<h3>How jsDoctrineSchemaOverriderPlugin Fixes The Problem</h3>
<p>The brilliant part of symfony&#8217;s model design is the idea where there&#8217;s a base class and an inheriting class for each model. For example, if you have a table in your database called <code>animal</code>, symfony creates an <code>Animal</code> class as well as a <code>BaseAnimal</code> class. Then, when you re-run <code>symfony doctrine:build-model</code>, <code>BaseAnimal</code> is wiped out and rewritten but <code>Animal</code>&mdash;the class you&#8217;re allowed to custmize&mdash;is left undisturbed. If you&#8217;re familiar with this idea, you&#8217;ll understand how jsDoctrineSchemaOverriderPlugin works.</p>
<p>The meat of jsDoctrineSchemaOverriderPlugin is in two classes: BaseSchema and Schema. Like symfony&#8217;s models, BaseSchema is auto-generated and Schema is there for you to override BaseSchema. <code>BaseSchema</code> is automatically built by jsDoctrineSchemaOverriderPlugin as a direct reflection of your database structure and Schema is where you can edit that structure. And get this: you <em>don&#8217;t</em> have to re-do all your work each time you rebuild the schema!</p>
<h3>Installation</h3>
<pre>$ symfony plugin:install http://jasonswett.net/jsDoctrineSchemaOverriderPlugin-0.1.0.tgz</pre>
<h3>Examples</h3>
<h4>Removing an Entity</h4>
<p>Let&#8217;s first take a trivial example: you have an view called <code>my_view</code> that you don&#8217;t want a model for. Edit your <code>plugins/jsDoctrineSchemaOverriderPlugin/lib/Schema.class.php</code> by adding a line to unset this view:</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: #000000; font-weight: bold;">class</span> Schema <span style="color: #000000; font-weight: bold;">extends</span> BaseSchema
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entities</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'MyView'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now, instead of running <code>symfony doctrine:build-schema</code>, you&#8217;ll do something a little different. Run:</p>
<pre>$ symfony schema-overrider:build-schema</pre>
<p>You&#8217;ll want to always run <code>schema-overrider:build-schema</code> instead of <code>doctrine:build-schema</code>. This ensures that the overrides you make in <code>Schema.class.php</code> are reflected in your <code>schema.yml</code>.</p>
<p>That&#8217;s the simplest case: completely wiping out an entity. What if we want to edit an entity&#8217;s attributes?</p>
<h4>Overriding Attributes</h4>
<p>Let&#8217;s say we have two classes, <code>Animal</code> and <code>Horse</code>, with <code>Horse</code> inheriting from <code>Animal</code>. If you just run <code>symfony doctrine:build-schema</code>, symfony will have no idea just by looking at your database schema that Horse inherits from Animal. You can make sure symfony knows about this inheritance by adding the following to <code>plugins/jsDoctrineSchemaOverriderPlugin/lib/Schema.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>
<span style="color: #000000; font-weight: bold;">class</span> Schema <span style="color: #000000; font-weight: bold;">extends</span> BaseSchema
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<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;">entities</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Horse'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'connection'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'doctrine'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'tableName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'horse'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'inheritance'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'extends'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Animal'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'concrete'</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: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Just like in the first example, we&#8217;ll run this command:</p>
<pre>$ symfony schema-overrider:build-schema</pre>
<p>Now Horse will always inherit from Animal and you won&#8217;t have to keep copying and pasting every time you run <code>build-schema</code>.</p>
<h3>Please Help!</h3>
<p>If you have any feedback of any kind about this plugin, please feel free to leave me a comment and let me know. I don&#8217;t know if I&#8217;m going about this the right way and I don&#8217;t know if my documentation is clear enough for other people to be able to use my plugin. All I know is that it works for me and it saves me a ton of work. Any feedback you have would be greatly appreciated!</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonswett.net/jsdoctrineschemaoverriderplugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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. Here&#8217;s how to do a transaction with Doctrine. This is essentially lifted from the official Doctrine documentation but it&#8217;s a little more to-the-point than theirs. Plus my version doesn&#8217;t fail silently.

&#60;?php
$conn = Doctrine_Manager::connection&#40;&#41;;
&#160;
try
&#123;
  $conn-&#62;beginTransaction&#40;&#41;;
&#160;
  $myObject-&#62;save&#40;&#41;;
  $myOtherObject-&#62;save&#40;&#41;;
&#160;
 [...]]]></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>. Here&#8217;s how to do a transaction with Doctrine. This is essentially lifted from the <a href="http://www.doctrine-project.org/projects/orm/1.2/docs/cookbook/creating-a-unit-of-work-using-doctrine/en">official Doctrine documentation</a> but it&#8217;s a little more to-the-point than theirs. Plus my version doesn&#8217;t fail silently.</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>

]]></content:encoded>
			<wfw:commentRss>http://jasonswett.net/transactions-with-doctrine/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>
