[Slick 2.0] map to Option[String] in a case class cause compiling error

107 views
Skip to first unread message

Zhao Wang

unread,
Mar 8, 2014, 2:58:13 PM3/8/14
to scala...@googlegroups.com
Hi I have the following simple code generating a compile error seems to be conflict with what the document says:

case class Task(id: Option[Int], title: String, note: Option[String])
class Tasks(tag: Tag) extends Table[Task](tag, "task") {
  def id   = column[Int]("title", O.PrimaryKey, O.AutoInc)
  def title  = column[String]("title")
  def street = column[Option[String]]("note")

  def * = (id.?, title, street.?) <> (Task.tupled, Task.unapply)
}

It will generate a compile error:

[error] /Users/admin/workspace/play/demo/app/models/Test.scala:36: could not find implicit value for evidence parameter of type scala.slick.ast.BaseTypedType[Option[String]]
[error]   def * = (id.?, title, street.?) <> (Task.tupled, Task.unapply)
[error]                         ^
[error] one error found
[error] (compile:compile) Compilation failed

In the Slick 2.0 document, it says "Nullable columns are represented by Option[T] where T is one of the supported primitive types." at http://slick.typesafe.com/doc/2.0.0/schemas.htmlSo I suppose this should work.

Do I miss something here? Thanks. 

Christopher Vogt

unread,
Mar 10, 2014, 10:00:36 PM3/10/14
to scala...@googlegroups.com
> def * = (id.?, title, street.?) <> (Task.tupled, Task.unapply)

User street instead of street.?
Street is already an Option. no need for .? Does that help?

Chris

Zhao Wang

unread,
Mar 10, 2014, 10:38:15 PM3/10/14
to scala...@googlegroups.com
I see. It does solve the problem. I misunderstood how .? works. By looking at the source code, I now see how it works.

Thanks for the help.  :)
Reply all
Reply to author
Forward
0 new messages