【问题标题】:Type error when trying to use mapped projection with Slick尝试将映射投影与 Slick 一起使用时出现类型错误
【发布时间】:2013-02-05 05:01:58
【问题描述】:

我正在尝试使用 Slick 的映射投影(版本 1.0.0-RC1)。但是以下代码遵循网站上的示例(因为似乎没有任何适当的文档或可用的 scaladocs)会产生类型错误:

object PDFDocs extends Table[(String,Option[String],String)]("DOCUMENTS"){
  def id = column[String]("ID", O.PrimaryKey)
  def title = column[Option[String]]("TITLE")
  def tags = column[String]("TAGS")
  def * = (id ~ title ~ tags).<>[PDFDocument](PDFDocument,PDFDocument unapply _)
}

case class PDFDocument(name: String,
                       title: Option[String],
                       tags: String)

这是产生的错误:

error: type mismatch; 
found: scala.slick.lifted.MappedProjection[docman.rdb.PDFDocument,(String,Option[String], String)] 
required: scala.slick.lifted.ColumnBase[(String, Option[String], String)] 
def * = (id ~ title ~ tags).<>[PDFDocument](PDFDocument,PDFDocument unapply _)

【问题讨论】:

    标签: scala slick


    【解决方案1】:

    在我的脑海中,第一行不应该是:

    object PDFDocs extends Table[PDFDocument]("DOCUMENTS") {
    

    【讨论】:

    • 这“甚至”更好,并且有效。谢谢,我在示例中忽略了这一点。
    • +100。我一直在寻找答案,我查看的所有样本都根据成员参数化了表类,而不是作为一个完整的模型案例类。我整天都在用头撞墙。谢谢。
    猜你喜欢
    • 2019-11-20
    • 2022-08-14
    • 2019-11-04
    • 2011-01-11
    • 1970-01-01
    • 1970-01-01
    • 2012-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多