使用 Slick,我试图将数据库表条目直接投影到它们代表的案例类。关注 example in the documentation ,我使用 <> 设置了映射投影运算符(operator):
case class SomeEntity3(id: Int, entity1: Int, entity2: Int)
val SomeEntityTable = new Table[SomeEntity3]("some_entity_table") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def entity1 = column[Int]("entity1")
def entity2 = column[Int]("entity2")
def * = id ~ entity1 ~ entity2 <> (SomeEntity3, SomeEntity3.unapply _)
}
现在,我想向 SomeEntity3 添加一些静态常量和辅助方法。为此,我创建了一个伴生对象。但只要我包括这条线
object SomeEntity3
* 的定义弹出了一个非常疯狂的多行错误说一些难以辨认的关于“重载方法值 <> 与替代品”。
伴随对象如何与 Slick 中的双向映射相关,我能否以某种方式实现我的目标?
请您参考如下方法:
修复很简单:
def * = id ~ entity1 ~ entity2 <> (SomeEntity3.apply _, SomeEntity3.unapply _)




