title: Doctrine DQL, class table inheritance and access to subclass fields
body: <p>I have a problem with a DQL query and entity specialization. </p>
  
  <p>I have an Entity called <code>Auction</code>, which is <code>OneToOne</code> relation with <code>Item</code>. <code>Item</code> is a <code>mappedSuperclass</code> for <code>Film</code> and <code>Book</code>. I need a query that could back a search engine, allowing the user to look for auctions with different properties <code>AND</code> selling items with different properties (it is the <code>AND</code> part that makes it challenging). </p>
  
  <p>The problem is that even though <code>Auction</code> has an association pointing to <code>Item</code> as such, I need to have access to <code>Film</code>- and <code>Book</code>-specific fields. The users will specify the <code>Item</code> type they're looking for, but I don't see any way of using this information other than using <code>INSTANCE OF</code> in my DQL query. </p>
  
  <p>So far, I have tried using a query like: </p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT a FROM Entities\Auction a
      INNER JOIN a.item i 
      INNER JOIN i.bookTypes b 
      WHERE i INSTANCE OF Entities\Book 
      AND b.type = 'Fantasy' 
      AND ...". 
  </code></pre>
  
  <p>Such a query results in an error saying that:</p>
  
  <blockquote>
    <p>Class <code>Entities\Item</code> has no field or association named <code>bookTypes</code></p>
  </blockquote>
  
  <p>which is false for <code>Book</code>, yet true for <code>Item</code>.</p>
  
  <p>I have also tried </p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT a FROM Entities\Book i 
      INNER JOIN i.auction a ...
  </code></pre>
  
  <p>but I reckon Doctrine requires that I refer to the same Entity in <code>SELECT</code> and <code>FROM</code> statements. </p>
  
  <p>If that's of importance, I am using class table inheritance. Still, I don't think switching to single table inheritance would do the trick. </p>
  
  <p>Any ideas?</p>