0

我收到以下错误,但我不明白出了什么问题。

could not find implicit value for parameter tm: scala.slick.ast.TypedType[I] 
[error]   def id = column[I]("id",O.PrimaryKey) 
[error]                     ^

此错误涉及 FkTable。我已经列出了代码以及表明我意图的注释。我的计划是为表格打下良好的基础,然后我可以使用这些表格来完成我的 CRUD 服务。

//ROWS
trait Row[I<:AnyVal,M[_]]{
  val id:M[I]
}
//TABLES
/**
 * @tparam I This is the type of the ID column in the table
 * @tparam M The row may contain a wrapper (such as Option) which communicates extra information to Slick for the row
 *           data.  M can be Id, which means that M[I] == Id[I] == I which means the Row item can contain a simple type.
 * @tparam R The class that represents a row of data.  As explained above, it is described by its __id__ which is of
 *           type M[I].
 */
abstract class BasicTable[I <:AnyVal,M[_], R <:Row[I,M]](tag: Tag, name: String) extends Table[R](tag, name) {
  def id: Column[I]
}

/**
 * @note The BasicTable takes Long,Option because longs can be incremented, and in slick this is communicated by an
 *       Option value of None. The None is read and tells Slick to generate the next id value.  This implies that the
 *       Row (R) must have a value __id__ that is an Option[Long], while the id column must remain Long.
 */
abstract class IncrTable[R <: Row[Long,Option]](tag: Tag, name: String) extends BasicTable[Long,Option,R](tag, name){
  def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
}

/**
 *
 * @param refTable
 * @tparam I This is the type of the ID column in the table
 * @tparam R The class that represents a row of data.  As explained above, it is described by its __id__ which is of
 *           type M[I].
 * @tparam M2 The Wrapper for the referenced table's id value
 * @tparam R2 The class that represents the referenced table's row of data
 */
abstract class FkTable[I<: AnyVal,R<:Row[I,Id],M2[_], R2 <:Row[I,M2]](tag: Tag, name: String,refTable:TableQuery[BasicTable[I,M2,R2]]) extends BasicTable[I,Id,R](tag, name){
  def id = column[I]("id", O.PrimaryKey)

  //Foreign Key
  def fkPkconstraint = foreignKey("PK_FK", id, refTable)(_.id)
}
4

1 回答 1

4

Slick要求在其签名中def column[T]隐含。TypedType[T]Slick 附带TypedTypes 用于Int, Double,Date等,但它找不到任何泛型类型I。您可以在构造函数中请求一个FkTable. 只需将第二个参数列表添加到 FkTable 为(implicit tt: TypedType[I])

abstract class FkTable[...](...)(implicit tt: TypedType[I]) extends ...

这会将隐式查找移动到FkTable使用的位置,并且I可能设置为更具体的类型。然后将该TypedType值隐式传播到对 的调用column[I]

于 2014-06-19T21:02:14.293 回答