title: Doctrine 2 Class Table Inheritance YML
body: <p>I'm trying to use Class Table Inheritance within ZF2 and Doctrine 2.  My implementation is pretty simple.  I think I have the class structure all set, but I think there might be a problem with some setup somewhere.  Unfortunately, I have found a lot of documentation on the Class setup, but not a whole lot on the YML implementation.  Everyone seems to resort to using the doctrine tools to generate everything.  With how things are set up, using the doctrine tools is a little problematic, especially when using ZF2.  Also, I consider this to be a learning opportunity.  So, here is what I have:</p>
  
  <p>The Current Problem:  I'm not getting any of the data from the child class/table:</p>
  
  <pre><code>.array(1) {
  [0] =&gt;
  class MyCompany\Domain\Model\Customer\CustomerNote#2852 (9) {
    protected $customer =&gt;
    NULL
    protected $note =&gt;
    string(13) "Clever Note 1"
    protected $id =&gt;
    string(1) "1"
    protected $disabled =&gt;
    NULL
    protected $modified =&gt;
    class DateTime#2884 (3) {
  
      ...
  </code></pre>
  
  <p>The Generic Notes Class/Table:</p>
  
  <pre><code>CREATE TABLE generic_notes
  (
    note_id serial NOT NULL,
    discriminator character varying(255) NOT NULL, 
    note text,
    created timestamp with time zone NOT NULL DEFAULT now(),
    created_by_id bigint NOT NULL,
    modified timestamp with time zone,
    modified_by_id bigint,
    disabled timestamp with time zone NOT NULL DEFAULT 'infinity'::timestamp with time zone,
    CONSTRAINT generic_notes_pkey PRIMARY KEY (note_id),
    CONSTRAINT generic_notes_created_by_id_fkey FOREIGN KEY (created_by_id)
        REFERENCES users (user_id) MATCH SIMPLE
        ON UPDATE CASCADE 
        ON DELETE RESTRICT,
    CONSTRAINT generic_notes_modified_by_id_fkey FOREIGN KEY (modified_by_id)
        REFERENCES users (user_id) MATCH SIMPLE
        ON UPDATE CASCADE 
        ON DELETE RESTRICT
  )
  </code></pre>
  
  <p>The Customer Notes Class/Table (Inherits Generic Notes):</p>
  
  <pre><code>CREATE TABLE customer_notes
  (
    note_id bigint NOT NULL,
    customer_id bigint NOT NULL,
    CONSTRAINT customer_notes_pkey PRIMARY KEY (note_id),
    CONSTRAINT customer_notes_note_id_fkey FOREIGN KEY (note_id)
        REFERENCES generic_notes (note_id) MATCH SIMPLE
        ON UPDATE RESTRICT 
        ON DELETE RESTRICT,
    CONSTRAINT customer_notes_customer_id_fkey FOREIGN KEY (customer_id)
        REFERENCES customers (customer_id) MATCH SIMPLE
        ON UPDATE R1ESTRICT 
        ON DELETE RESTRICT
  )
  </code></pre>
  
  <p>YML Mapping for Note:</p>
  
  <pre><code>MyCompany\Domain\Model\Note:
    type: entity
    table: generic_notes
    inheritanceType: JOINED
    discriminatorColumn:
      name: discriminator
      type: string
      length: 255
    discriminatorMap:
      customer: MyCompany\Domain\Model\Customer\CustomerNote
    id:
      id:
        column: note_id
        type: bigint
        generator:
          strategy: IDENTITY
    fields:
      note:
        type: text
        nullable: true
      created:
        type: datetimetz
      modified:
        type: datetimetz
        nullable: true
      disabled:
        type: datetimetz
        nullable: true
    manyToOne:
      createdBy:
        targetEntity: MyCompany\Domain\Model\User
        joinColumn:
          name: created_by_id
          referencedColumnName: user_id
      modifiedBy:
        targetEntity: MyCompany\Domain\Model\User
        joinColumn:
          name: modified_by_id
          referencedColumnName: user_id
  </code></pre>
  
  <p>Customer Note Mapping:</p>
  
  <pre><code>MyCompany\Domain\Model\Customer\CustomerNote:
    type: entity
    table: customer_notes
    manyToOne:
      customer:
        targetEntity: MyCompany\Domain\Model\Customer
        inversedBy: customerNote
        joinColumn:
          name: customer_id
          referencedColumnName: customer_id
  </code></pre>
  
  <p>Generic Note Entity</p>
  
  <pre><code>&lt;?php
  
  namespace MyCompany\Domain\Model;
  
  use MyCompany\Domain\Model\Entity\AbstractEntity;
  use MyCompany\Domain\Model\Entity\DisabledTrait;
  use MyCompany\Domain\Model\Entity\TimestampedInterface;
  use MyCompany\Domain\Model\Entity\TimestampedTrait;
  
  /**
   * Class Note
   *
   * @package MyCompany\Domain\Model
   */
  
  class Note extends AbstractEntity implements TimestampedInterface
  {
      use DisabledTrait;
      use TimestampedTrait;
  
      /**
       * @var string
       */
      protected $note;
  
      /**
       * @param string $note
       * @return $this
       */
      public function setNote($note)
      {
          $this-&gt;note = $note;
          return $this;
      }
  
      /**
       * @return string
       */
      public function getNote()
      {
          return $this-&gt;note;
      }
  }
  </code></pre>
  
  <p>Customer Note Entity:</p>
  
  <pre><code>&lt;?php
  
  namespace MyCompany\Domain\Model\Customer;
  
  use MyCompany\Domain\Model\Note;
  use MyCompany\Domain\Model\Customer;
  
  /**
   * Class CustomerNote
   * @package MyCompany\Domain\Model\Customer
   */
  class CustomerNote extends Note
  {
      /**
       * @var \MyCompany\Domain\Model\Customer
       */
      protected $customer;
  
      /**
       * @param \MyCompany\Domain\Model\Customer $customer
       * @return $this
       */
      public function setCustomer(Customer $customer)
      {
          $this-&gt;customer = $customer;
          return $this;
      }
  
      /**
       * @return \MyCompany\Domain\Model\Customer
       */
      public function getCustomer()
      {
          return $this-&gt;customer;
      }
  }
  </code></pre>
  
  <p>Generic Note Fixture Data:</p>
  
  <pre><code>generic_notes:
    -
      note_id: 1
      discriminator: customer
      note: Clever Note 1
      created: "2012-01-23 05:43:21.000000"
      created_by_id: 1
      modified: "2012-01-24 05:43:21.000000"
      modified_by_id: 2
      disabled: null
  </code></pre>
  
  <p>Customer Notes Fixture Data:</p>
  
  <pre><code>customer_notes:
    -
      note_id: 1
      customer_id: 1
  </code></pre>