为什么浮油不能存储Option [String]?

时间:2013-12-29 04:04:59

标签: scala playframework-2.0 slick

我在playframework 2.2项目中使用了slick 2.0 rc1  我的talbe代码是:

case class Resource(id: Option[Long] = None, owner: UserId, types: String)

// The static object that does the actual work - note the names of tables and fields in H2 are case sensitive and must be all caps 
object Resources extends Table[Resource]( "RESOURCE") {
  def id = column[Long]("ID", O.PrimaryKey, O.AutoInc)
  def owner = column[UserId]("Owner")
  def types = column[String]("Type")
  def withuser = foreignKey("User_FK", owner, Users)(_.id)

 // Every table needs a * projection with the same type as the table's type parameter
 def * = id.? ~ owner ~ types <> (Resource, Resource.unapply _)
}

输出错误是:

[info] Compiling 16 Scala sources and 2 Java sources to C:\assigment\slick-advan
ced\target\scala-2.10\classes...
[error] C:\assigment\slick-advanced\app\models\Resource.scala:12: overloaded met
hod constructor Table with alternatives:
[error]   (_tableTag: scala.slick.lifted.Tag,_tableName: String)play.api.db.slic
k.Config.driver.Table[models.Resource] <and>
[error]   (_tableTag: scala.slick.lifted.Tag,_schemaName: Option[String],_tableN
ame: String)play.api.db.slick.Config.driver.Table[models.Resource]
[error]  cannot be applied to (String)
[error] object Resources extends Table[Resource]( "RESOURCE") {
[error]                  ^

我在文档上知道它:

 object Resources(tag: Tag) extends TableTable[(Long, UserId, String)](tag, "RESOURCE") {

但在我更改之后,它仍然有错误:

[error] C:\assigment\slick-advanced\app\models\Resource.scala:12: traits or obje
cts may not have parameters
[error] object Resources(tag: Tag) extends TableTable[(Long, UserId, String)](ta
g, "RESOURCE") {
[error]                 ^
[error] one error found

1 个答案:

答案 0 :(得分:1)

查看构造函数Table的{​​{3}}:

new Table(_tableTag: Tag, _tableName: String)
new Table(_tableTag: Tag, _schemaName: Option[String], _tableName: String)

编译器告诉您有这些选择,但两者都没有。您只需Table即可构建名为Resources的{​​{1}}实例。如您所见,这不是一种选择。没有双关语。

Scaladoc表明您的声明应该更像这样:

String