title: Case class inheritance is prohibited, but how to model dependency from library?
body: <p>I have three distinct Scala projects, one of them consists of only models which are used in both of the other Scala projects (hereinafter referred to as library). One of the three projects is a Play web application and I want to persist the models from the library in MongoDB (code resides in Play app).</p>
  
  <p>So in my library I have the following model:</p>
  
  <pre><code>case class MyUser(id: UUID = UUID.randomUUID(), timestamp: Instant = Instant.now, name: String)
  </code></pre>
  
  <p>To persist instances of <code>MyUser</code> in my Play app, I would usually go with this model:</p>
  
  <pre><code>case class MyUser(var _id: Option[BSONObjectID] = None,
                     id: UUID,
                     timestamp: Instant,
                     name: String,
                     var created: Option[DateTime] = None,
                     var updated: Option[DateTime] = None
                    ) extends Temporal
  </code></pre>
  
  <p>Now I am searching for a way to morph <code>MyUser</code> of my library to the corresponding class in my Play app, so I thought I would do something like this:</p>
  
  <pre><code>case class MyUser(var _id: Option[BSONObjectID] = None,
                     var created: Option[DateTime] = None,
                     var updated: Option[DateTime] = None
                    ) extends lib.MyUser with Temporal
  </code></pre>
  
  <p>However, now I get the following error:</p>
  
  <blockquote>
    <p>case-to-case inheritance is prohibited. To overcome this limitation, use extractors to pattern match on non-leaf nodes.</p>
  </blockquote>
  
  <p>I thought about doing something like this:</p>
  
  <pre><code>case class MyUser(var _id: Option[BSONObjectID] = None,
                     user: lib.MyUser,
                     var created: Option[DateTime] = None,
                     var updated: Option[DateTime] = None
                    ) extends Temporal
  </code></pre>
  
  <p>How can I design this the right way?</p>