Hi,
I need help with one problem in Slick when I query field of Enumeration type.
I have table defined as:
class Animals(tag : Tag) extends Table[Animal](tag, "animal") {
implicit val AnimalTypeMapper = MappedColumnType.base[AnimalType.Value, String](
s => s.toString,
s => AnimalType.withName(s)
)
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def kind = column[AnimalType.Value]("kind")
def * = (id.?, name, kind) <> (Animal.tupled, Animal.unapply)
}
case class and enumeration defined as:
case class Animal(id : Option[Long], name: String, kind: AnimalType.Value)
object AnimalType extends Enumeration {
val CAT, DOG = Value
}
When I try to query for animal kind only:
val animals = TableQuery[Animals]
animals.map(_.type).result
The following exception is thrown:
No matching Shape found.
Slick does not know how to map the given types.
Possible causes: T in Table[T] does not match your * projection. Or you use an unsupported type in a Query (e.g. scala List).
Required level: slick.lifted.FlatShapeLevel
Source type: slick.lifted.Rep[db.tables.AnimalType.Value]
Unpacked type: T
Packed type: G
When I query for id or name everything is fine.
Please help me with this one, I think I tried everything but I can't make it work.