I have the following situation/code;
trait Model { def myField: String } case class MyModel(myField: String) extends Model In the traditional model of creating DAOs for my model classes I want to create a DAO trait that contains some generic CRUD operations. NOTE...the persistence framework doesn't matter here...the question is around using case class methods within a trait that is using generics.
With that said I want to create the following trait;
trait DAO[M <: Model] { def insert(model: M): M = { ... do work m.copy(myField="someval") } } In this case the code does not compile because generic M knows nothing about being a "case class". If there some easy solution here, can a generic be declared as needing to be a type of case? Or should the Model trait declare a copy method that any extending class has to implement and by being a case class it does so?