我在 Play 中使用 Slick 3.0。我有一个我写过数据库映射的小班
case class Person(id: Int, firstname: String, lastname: String)
class People(tag: Tag) extends Table[Person](tag, "PEOPLE") {
def id = column[Int]("PERSON_ID", O.PrimaryKey, O.AutoInc)
def firstname = column[String]("PERSON_FIRST_NAME")
def lastname = column[String]("PERSON_LAST_NAME")
def * = (id, firstname, lastname) <> (Person.tupled, Person.unapply _)
}
这编译并完美运行。现在我创建了一个 HTML 表单,我将在其中进行数据输入,并且我需要将 HTML 表单绑定到 Person 对象。所以我写了
object Person {
val form = Form(mapping(
"id" -> number,
"firstname" -> text,
"lastname" -> text
)(Person.apply)(Person.unapply))
}
但是现在我收到一条错误消息
[error] /Users/abhi/ScalaProjects/MyPlay1/app/tables/PersonDAO.scala:18: value tupled is not a member of object models.Person
[error] def * = (id, firstname, lastname) <> (Person.tupled, Person.unapply _)
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 4 s, completed Jun 28, 2015 4:37:50 PM
Mohitas-MBP:MyPlay1 abhi$
因此,似乎添加伴随对象会破坏我的数据库映射代码。早些时候它在案例类上寻找元组属性,但现在它正在寻找对象并且它没有找到它。
我怎样才能拥有案例类,然后是数据库映射和表单映射?