title: Scala trait function: return instance of derived type
body: <p>I have a trait Book that looks like this</p>
  
  <pre><code>trait Book{
   val sqlTableName;
   def getAll: Seq[ Book ] = { magicSQLFn( $"SELECT * FROM $sqlTableName" ) }
  }
  </code></pre>
  
  <p>I have two derived types:</p>
  
  <pre><code>class Fiction extends Book{ val sqlTableName = "fiction" }
  class NonFiction extends Book{ val sqlTableName = "nonfiction" );
  </code></pre>
  
  <p>I need to get <code>Seq[Fiction]</code> when I call <code>getAll</code> on an instance of  <code>Fiction</code>, say <code>fiction1</code>. I know one way to do would be to do a <code>.map( _.asInstanceOf[ Fiction ] )</code>. However, is there a way to avoid this altogether? </p>
  
  <p>Actually, I realize the less wrong way to do would be to be able to define a companion object for <code>Fiction</code> that extends <code>Book</code> so that I can call <code>getAll</code> on that object (as opposed to doing it on an instance), however, in that case, I'm not sure how I'll convert the individual elements in the returned sequence to instances of <code>Fiction</code> class because <code>Fiction</code> class will no longer derive from <code>Book</code>. 
  Should I have two differently named <code>Book</code> traits? One that is the super of these objects, and the other that is the super class of these classes? </p>
  
  <p>EDIT: @Travis Brown's reply solves my initial problem. If anyone have comments on how to handle this using companion objects and not class instances, that'd be great too!</p>