I have a model that is composed of three case classes as below:
case class MyModel(myId: MyIdType, name: MyNameType)
case class MyIdType(id: Long)
case class MyNameType(name: String)
object MyNameType(name: String) {
val NAME1 = MyNameType("name1")
val NAME2 = MyNameType("name2")
val NAME3 = MyNameType("name3")
}
Let's say these are the existing models. I have a Slick table mapping that goes like this:
class MyTable(tag: Tag) extends Table[MyTableElem](tag, "myTable") {
def id = column[Long]("id", O.PrimaryKey)
def name = column[String]("name")
def * = (id, name) <> (MyTableElem.tupled, MyTableElem.unapply)
}
As it can be seen that I have to have another type to map my table MyTable first to MyTableElem and then during every read, I transform the MyTableElem to MyModel. Is there a way to avoid this and go directly to the MyModel? I guess I have to implement the tupled and unapply methods or?