edwardborner
edwardborner

Reputation: 237

Play framework: Slick does not know how to map the given types

I am trying to use slick in the play framework but struggling with even the simplest of examples.

Here is my code:

case class Account (
  id: Int,
  email: String,
  password: String,
  permission: String
)

class Accounts(tag: Tag) extends Table[Account](tag, "account") {
  def id = column[Int]("id")
  def email = column[String]("email")
  def password = column[String]("password")
  def permission = column[String]("permission")

  def * = (id, email, password, permission)
}

When I compile this I get the following error:

play.PlayExceptions$CompilationException: Compilation error[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: scala.slick.lifted.ShapeLevel.Flat
     Source type: (scala.slick.lifted.Column[Int], scala.slick.lifted.Column[String], scala.slick.lifted.Column[String], scala.slick.lifted.Column[String])
   Unpacked type: models.Account
     Packed type: Any
]

Can anyone tell me if I have something wrong here?

Thanks

Further Details:

Upvotes: 2

Views: 5665

Answers (2)

edwardborner
edwardborner

Reputation: 237

I have found the issue. I have a companion object that was conflicting

If you have a companion object you need to use a slightly different syntax for your * projection:

def * = (id, email, password, permission) <> ((Account.apply _).tupled, Account.unapply)

Upvotes: 16

Pawel Wlodarski
Pawel Wlodarski

Reputation: 59

according to http://slick.typesafe.com/doc/2.0.2/schemas.html, I think that you "*" projection method should look like this:

def * = (id, email, password, permission) <> (Account.tupled, Account.unapply)

Upvotes: 3

Related Questions