title: Doctrine and inheritance mapping: association on a child entity
body: <p>I'm trying to query an entity and joined an other entity which is a child in an inheritance mapping structure.</p>
  
  <p>The situation is:</p>
  
  <ul>
  <li>I have a parent entity (eg. Animal)</li>
  <li>I have a child entity (eg. Dog)</li>
  <li>I have an entity with a 1:1 association to the child (Dog House)</li>
  </ul>
  
  <p>I want to query all the dog houses and doctrine to get me their dog owners as well.</p>
  
  <p>The simple DQL query I wrote is:</p>
  
  <pre><code>SELECT o FROM MyBundle:DogHouse h JOIN h.dog d
  </code></pre>
  
  <p>The error is:</p>
  
  <blockquote>
    <p>Notice: Undefined index: id in
    ../vendor/doctrine/lib/Doctrine/ORM/Query/SqlWalker.php
    line 779, class: ErrorException</p>
  </blockquote>
  
  <p>Looking at the stack trace it seems that doctrine is trying to join with the id on the child entity instead of the parent</p>
  
  <p>Here is the classes illustrating this case</p>
  
  <pre><code>/**
   *  Animal
   *
   * @ORM\Entity
   * @ORM\Table(name="animal")
   * @ORM\InheritanceType("JOINED")
   * @ORM\DiscriminatorColumn(name="type", type="integer")
   * @ORM\DiscriminatorMap({"1"="cat",  "2"="dog"})
   */
  class Animal
  {
      /**
       * @ORM\Column(name="animal_id", type="integer", nullable=false)
       * @ORM\Id
       */
      protected $id;
  
      /**
       * @ORM\Column(name="name", type="string", length=200, nullable=false)
       */
      protected $name;
  
      /* getters, setters... */
  }
  
  /**
   * Dog
   *
   * @ORM\Entity
   * @ORM\Table(name="dog")
   */
  class Dog extends Animal
  {
      /**
       * @ORM\OneToOne(targetEntity="DogHouse", inversedBy="dog")
       */
      private $dogHouse;
  
      /* getters, setters... */
  }
  
  
  /**
   * Dog House
   * 
   * @ORM\Table(name="dog_house")
   * @ORM\Entity
   */
  class DogHouse
  {
      /**
       * @ORM\Column(name="dog_house_id", type="integer", nullable=false)
       * @ORM\Id
       */
      private $id;
  
      /**
       * @ORM\OneToOne(targetEntity="Dog", mappedBy="doghouse")
       */
      private $dog;
  
      /* getters, setters... */
  }
  </code></pre>
  
  <p>Note:
  <a href="https://groups.google.com/group/doctrine-user/browse_thread/thread/c48af49a33c8f9fa/c9528deaf08987c4#c9528deaf08987c4" rel="nofollow">This post</a> relates to the exact same problem and wasn't answered</p>