title: Copy all the fields of a case class when only the mixed in trait is known
body: <p>First of all, I saw a few similar questions in SO and other forums, but many were for older versions of Scala. I was hoping if there is any other way possible for my situation. Also, I posted the same question in <a href="https://groups.google.com/forum/#!topic/scala-user/lEIcKyV89xE" rel="nofollow">scala</a> and <a href="https://groups.google.com/forum/#!topic/scala-user/lEIcKyV89xEhttps://groups.google.com/forum/#!topic/scala-user/lEIcKyV89xE" rel="nofollow">slick</a> google groups, but did not receive any suggestion yet. So was hoping if anyone here could give some suggestions.</p>
  
  <p>I have the below traits/abstract classes in my application.</p>
  
  <pre><code>trait Persistable
  
  abstract class BaseEntity extends Persistable {
    val id: Long
  }
  
  trait Auditable {
    val createdDate: java.sql.Timestamp
    val modifiedDate : java.sql.Timestamp
  }
  </code></pre>
  
  <p>All the table which are auditable will have created and modified dates. 
  One of my case classes looks like this.</p>
  
  <pre><code>case class UserAccount(
    id: Long, 
    name: String, 
    createdDate: java.sql.Timestamp, 
    modifiedDate: java.sql.Timestamp
  ) extends BaseEntity with Auditable
  </code></pre>
  
  <p>My application is a <code>spray</code> and <code>slick</code> based REST application.
  I am parsing the json sent from the client side into the required case class.
  Now, I want to set the createdDate and modifiedDate in the application, rather than just saving what the client sends. There are two reasons for that, as I do not want to have timezone difference issues and also don't want anyone to mess up the createdDate/modifiedDate intentionally as well. </p>
  
  <p>I am following the repository pattern to handle all the database operation in a central location. </p>
  
  <pre><code> trait Repository[TTable &lt;: BaseTable[TEntity], TEntity &lt;: Persistable[Long]] {
  
    def insert(row: TTable#TableElementType): TEntity = {
      db.withSession { implicit session =&gt;
        if (row.isInstanceOf[Auditable]) {
          // set the modifiedDate and createdDate here
          (query returning query.map(obj =&gt; obj) += row).asInstanceOf[TEntity]
        } else {
          (query returning query.map(obj =&gt; obj) += row).asInstanceOf[TEntity]
        }
      }
    }
  
  }
  </code></pre>
  
  <p>How can I copy the whole <code>row</code> and modify only <code>createdDate</code> and <code>modifiedDate</code>. I guess this can be achieved by using <code>reflection</code>, but I read suggestions to avoid the reflection. Is there any other way to achieve this functionality. It is not just this case, I have a few other situations where if the case class is mixed in with another trait, modify some other fields.</p>