【问题标题】:Missing arguments for method unapply in slick缺少方法的参数 unapply in slick
【发布时间】:2018-12-27 00:28:24
【问题描述】:

我正在使用 Scala 和 Slick 开发应用程序。我有一个名为 CarAdvertisement 的表,它有一个模型

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)

你能告诉我我在这里缺少什么吗?

【问题讨论】:

    标签: scala slick


    【解决方案1】:

    你确定你也没有类似的错误

    找不到参数 tt 的隐含值: slick.ast.TypedType[选项[java.time.LocalDate]]
    def firstRegistration = columnOption[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
    

    或者您可以尝试使用最新的 Slick 代码与合并的PR #1349 Support java time。不幸的是,AFAIK 仍然没有正式发布这些更改。

    【讨论】:

    • 感谢您的快速更新。但我已经尝试过所有这些技巧。但不知何故对我不起作用。
    • @ChaitanyaWaikar,那么您应该提供一个真实的Minimal, Complete, and Verifiable example 我在答案中提供的代码似乎可以编译,请参阅here
    猜你喜欢
    • 1970-01-01
    • 2014-04-15
    • 1970-01-01
    • 2021-07-24
    • 1970-01-01
    • 1970-01-01
    • 2015-02-06
    • 2016-07-26
    • 1970-01-01
    相关资源
    最近更新 更多