代码之家  ›  专栏  ›  技术社区  ›  Chaitanya

slick中缺少方法unapply的参数

  •  0
  • Chaitanya  · 技术社区  · 7 年前

    我正在使用Scala和Slick开发一个应用程序。我有一张名为Caradvisement的桌子,上面有一个模型

    case class CarAdvertisementModel(id: Int, title: String, fuel: String, price: Int, isNew: Boolean, mileage: Option[Int], firstRegistration : Option[LocalDate])
    

    我正在尝试使用slick声明我的模式。我的代码如下

      private class CarAdvertisement(tag: Tag) extends Table[CarAdvertisementModel](tag, "CAR_ADVERTISEMENT") {
    
        def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
    
        def title = column[String]("title")
    
        def fuel = column[String]("fuel")
    
        def price = column[Int]("price")
    
        def isNew = column[Boolean]("isNew")
    
        def mileage = column[Option[Int]]("mileage")
    
        def firstRegistration = column[Option[LocalDate]]("firstRegistration")
    
        def * = (id, title, fuel, price, isNew, mileage,firstRegistration) <> ((CarAdvertisementModel.apply _).tupled, CarAdvertisementModel.unapply)
      }
    

    然而,最后一行

    CarAdvertisementModel.unapply)
    

    给我一个错误

    Missing arguments for method unapply(CarAdvertisementModel)
    

    你能告诉我我在这里遗漏了什么吗?

    1 回复  |  直到 7 年前
        1
  •  0
  •   SergGr    7 年前

    你确定你没有这样的错误吗

    找不到参数tt的隐式值: slick.ast.TypedType[选项[java.time.LocalDate]]

    如果您有一个,请尝试向代码中添加类似的内容

    private class CarAdvertisement(tag: Tag) extends Table[CarAdvertisementModel](tag, "CAR_ADVERTISEMENT") {
    
      // fast hack to support LocalDate
      implicit val localDateColumnType = MappedColumnType.base[LocalDate, java.sql.Date](java.sql.Date.valueOf, _.toLocalDate)
    
      // the rest of the code
    

    PR #1349 Support java time . 不幸的是,目前还没有官方发布这些更改。