在 Slick 中,如何实现 Table 的多个投影?

In Slick, how to implement multiple projections for a Table?

这是代码(我使用的是 Slick 2.1):

case class UserRecord(id: Long,
                             mID: String,
                             userName: Option[String],
                             firstName: Option[String],
                             lastName: Option[String],
                             fullName: Option[String],
                             email: String,
                             avatarUrl: Option[String],
                             createTime: Timestamp,
                             updateTime: Timestamp,
                             status: Int,
                             socialProviders: Int)

  case class UserProfile (
      userName: String,
      firstName: Option[String],
      lastName: Option[String],
      fullName: Option[String],
      email: String,
      avatarURL: Option[String])


class UserTable(tag: Tag) extends Table[UserRecord](tag, "User") {
  def id = column[Long]("id", O.AutoInc)

  def mID = column[String]("mID", O.PrimaryKey)

  def username = column[Option[String]]("username")

  def firstName = column[Option[String]]("firstname")

  def lastName = column[Option[String]]("lastname")

  def fullName = column[Option[String]]("fullname")

  def email = column[String]("email")

  def avatarUrl = column[Option[String]]("avataurl")

  def createTime = column[Timestamp]("createTime")

  def updateTime = column[Timestamp]("updateTime")

  def status = column[Int]("status")

  def socialProviders = column[Int]("socialProviders")

  def * = (id, mID, username, firstName, lastName, fullName,
    email, avatarUrl, createTime, updateTime, status, socialProviders) <>(UserRecord.tupled, UserRecord.unapply _)

  def profile = (username, firstName, lastName, fullName, email, avatarUrl) <> (UserProfile.tupled, UserProfile.unapply _)
}

我试图在 Table class 中创建两个映射 *profile,但是,Slick 对此抱怨:

[error] Slick does not know how to map the given types.
[error] Possible causes: T in Table[T] does not match your * projection. Or you use an unsupported type in a Query (e.g. scala List).
[error]   Required level: scala.slick.lifted.FlatShapeLevel
[error]      Source type: (scala.slick.lifted.Column[Option[String]], scala.slick.lifted.Column[Option[String]], scala.slick.lifted.Column[Option[String]], scala.slick.lifted.Column[Option[String]], scala.slick.lifted.Column[String], scala.slick.lifted.Column[Option[String]])
[error]    Unpacked type: (String, Option[String], Option[String], Option[String], String, Option[String])
[error]      Packed type: Any
[error]   def profile = (username, firstName, lastName, fullName, email, avatarUrl) <> (UserProfile.tupled, UserProfile.unapply _)
[error]                                                                             ^

我看到了一个关于这个的blog,但是它看起来很复杂而且没有解释..

有人对此有想法吗?谢谢!

Slick 期望用户名是 'profile' 投影中的 Option[String]

 case class UserProfile (
  userName: String, // Here
  firstName: Option[String],
  lastName: Option[String],
  fullName: Option[String],
  email: String,
  avatarURL: Option[String])

很明显,这里的 Slick 不知道如何将列映射到大小写 class。