title: Scala idiom for partial models?
body: <p>I am writing a HTTP REST API and I want strongly typed model classes in Scala e.g. if I have a car model <code>Car</code>, I want to create the following RESTful <code>/car</code> API:</p>
  
  <p>1) For <code>POST</code>s (create a new car):</p>
  
  <pre><code>case class Car(manufacturer: String, 
                 name: String, 
                 year: Int)
  </code></pre>
  
  <p>2) For <code>PUT</code>s (edit existing car) and <code>GET</code>s, I want tag along an <code>id</code> too:</p>
  
  <pre><code>case class Car(id: Long, 
                 manufacturer: String, 
                 name: String, 
                 year: Int)
  </code></pre>
  
  <p>3) For <code>PATCH</code>es (partial edit existing car), I want this partial object:</p>
  
  <pre><code>case class Car(id: Long, 
                 manufacturer: Option[String],
                 name: Option[String], 
                 year: Option[Int])
  </code></pre>
  
  <p>But keeping 3 models for essentially the same thing is redundant and error prone (e.g. if I edit one model, I have to remember to edit the other models).</p>
  
  <p>Is there a typesafe way to maintain all 3 models? I am okay with answers that use macros too.</p>
  
  <p>I did manage to combine the first two ones as following</p>
  
  <pre><code>trait Id {
    val id: Long
  }
  
  type PersistedCar = Car with Id 
  </code></pre>