【发布时间】:2017-04-25 03:55:01
【问题描述】:
我已经很习惯像这样编写标准的光滑样板代码了。
假设我正在创建一个名为 Foo 的表,其中包含列 id 和 name。我们可以写
case class Foo(id: Long, name: String)
final class FooTable(tag: Tag) extends Table[Foo](tag, "foo") {
def id = column[Long]("id")
def name = column[String]("name")
def * = (id, name) <> (Foo.tupled, Foo.unapply)
}
但是,如果我想要一个 Foo 只有一个名称的单列表怎么办。下面的代码无法编译,因为 Now Foo 没有元组方法了。
case class Foo(name: String)
final class FooTable(tag: Tag) extends Table[Foo](tag, "foo") {
def name = column[String]("name")
def * = (name) <> (Foo.tupled, Foo.unapply)
}
我在 SO 上找到了这个帖子
Scala projections in Slick for only one column
并将我的代码更改为
case class Foo(name: String)
final class FooTable(tag: Tag) extends Table[Foo](tag, "foo") {
def name = column[String]("email_address")
def * = (name)
}
但仍然无法编译
【问题讨论】: