2014-06-19 45 views
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

油滑的def column[T]要求在其簽名的隱式TypedType[T]。對於Int,Double,Date等,使用TypedType作爲潤滑油,但對於通用類型I找不到任何一個。您可以在構造函數中請求FkTable。只需添加第二個參數列表FkTable爲(implicit tt: TypedType[I])

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

這使隱含查找到使用FkTable,並且I可能是設置爲更具體的類型。然後將TypedType值隱式傳播到column[I]的調用。

+0

我不得不爲BaseTypedType [I]添加隱式以使工作ColumnExtensionMethods方法與I字段。 (光滑的3.2.1) – sunofkyuss