我将 PlayFramework 2.1.1 与 Slick 1.0.1 和 Play-Slick-Plugin 0.3.2 结合使用。
定义一个强制我的模型实现“forInsert”-Mapper 的抽象类失败,因为我无法指定正确的返回类型。我当前的定义导致下面的编译错误,但我根本无法追踪这个问题并提供正确的类型。
import play.api.db.slick.Config.driver.KeysInsertInvoker
abstract class Model[M]( val table: String ) extends Table[M]( table )
{
def id = column[Int]( "id", O.PrimaryKey, O.AutoInc )
def forInsert: KeysInsertInvoker[M, Int]
}
object Course extends Model[Course]( "course" )
{
...
def forInsert = name ~ room <> ( apply _, unapply _ ) returning id
}
[error] Course.scala:27: polymorphic expression cannot be instantiated to expected type;
[error] found : [RU]play.api.db.slick.Config.driver.KeysInsertInvoker[model.Course,RU]
[error] required: play.api.db.slick.Config.driver.KeysInsertInvoker[model.Course,Int]
[error] def forInsert = name ~ room <> ( apply _, unapply _ ) returning id
[error] ^
[error] one error found
[error] (sample/compile:compile) Compilation failed
[error] Total time: 3 s, completed 18.06.2013 03:38:24