<?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; PHP</title>
	<atom:link href="http://jasonswett.net/category/software-development/php/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>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>
