jordan3
jordan3

Reputation: 887

Slick Generic Create Error

I get the following error and I don't understand what's wrong.

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

This error refers to the FkTable. I've listed the code, along with the comments that show my intentions. My plan is to make a nice foundation for tables that I can then make my CRUD service off of.

//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)
}

Upvotes: 0

Views: 880

Answers (1)

cvogt
cvogt

Reputation: 11270

Slick's def column[T] requests an implicit TypedType[T] in its signature. Slick ships with TypedTypes for Int, Double, Date, etc., but it can't find any one for the generic type I. You can request one in the constructor to FkTable. Just add a second argument list to FkTable as (implicit tt: TypedType[I]):

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

This moves the implicit lookup to where FkTable is used, and I is probably set to a more concrete type. The TypedType value is then implicitly propagated through to the call to column[I].

Upvotes: 4

Related Questions