Mapped projection with <> to a case class with companion object in Slick

后端 未结 4 788
野趣味
野趣味 2021-02-10 00:30

With Slick, I am trying to project database table entries directly to the case class they represent. Following the example in the documentation, I set up a mapped projection usi

4条回答
  •  抹茶落季
    2021-02-10 00:56

    Personally, the partially applied apply method from the case class does not work with my setup and Slick 3.0.

    This however, works, burrowing to the proper tupled method indirectly:

    class WidgetTable(tag: Tag) extends Table[WidgetEntity](tag, "widget_tbl") {
    
        def id = column[Int]("id",O.PrimaryKey)
        def foo = column[String]("foo")
    
        override def * = (id,foo) <> ((WidgetEntity.apply _).tupled,WidgetEntity.unapply)
    }
    

    See the full details: https://stackoverflow.com/a/38589579/564157

提交回复
热议问题