type TableElementType
is abstract inside of class AbstractTable[A]
. Scala doesn't know about any relationship between A
and TableElementType
. class Table
on the other hand defines final type TableElementType = A
, which tells Scala about this relationship (and apparently Scala is smart enough to use the final
annotation to know that the relationanship even holds for a subtype T <: Table[A]
eventhough Table[A]
is not co-variant in A
).
So you need to use T <: Table[A]
instead of T <: AbstractTable[A]
. And because Table
is inside the Slick driver cake (as in cake pattern), you need to move your Crud into your cake as well. Cakes are viral.
trait Profile {
val profile: JdbcProfile
}
trait CrudComponent{ this: Profile =>
import profile.simple._
trait Crud[T <: Table[A], A] {
val qry: TableQuery[T]
def countAll()(implicit session: Session): Int = {
qry.length.run
}
def getAll()(implicit session: Session): List[A] = {
qry.list // <-- works as intended
}
}
}