Reputation: 9549
I use slick 2.0 rc1 in my playframework 2.2 project my talbe code is:
case class Resource(id: Option[Long] = None, owner: UserId, types: String)
// The static object that does the actual work - note the names of tables and fields in H2 are case sensitive and must be all caps
object Resources extends Table[Resource]( "RESOURCE") {
def id = column[Long]("ID", O.PrimaryKey, O.AutoInc)
def owner = column[UserId]("Owner")
def types = column[String]("Type")
def withuser = foreignKey("User_FK", owner, Users)(_.id)
// Every table needs a * projection with the same type as the table's type parameter
def * = id.? ~ owner ~ types <> (Resource, Resource.unapply _)
}
the output error is:
[info] Compiling 16 Scala sources and 2 Java sources to C:\assigment\slick-advan
ced\target\scala-2.10\classes...
[error] C:\assigment\slick-advanced\app\models\Resource.scala:12: overloaded met
hod constructor Table with alternatives:
[error] (_tableTag: scala.slick.lifted.Tag,_tableName: String)play.api.db.slic
k.Config.driver.Table[models.Resource] <and>
[error] (_tableTag: scala.slick.lifted.Tag,_schemaName: Option[String],_tableN
ame: String)play.api.db.slick.Config.driver.Table[models.Resource]
[error] cannot be applied to (String)
[error] object Resources extends Table[Resource]( "RESOURCE") {
[error] ^
I know on document it like:
object Resources(tag: Tag) extends TableTable[(Long, UserId, String)](tag, "RESOURCE") {
but after I change it, it still have error:
[error] C:\assigment\slick-advanced\app\models\Resource.scala:12: traits or obje
cts may not have parameters
[error] object Resources(tag: Tag) extends TableTable[(Long, UserId, String)](ta
g, "RESOURCE") {
[error] ^
[error] one error found
Upvotes: 1
Views: 281
Reputation: 30310
Check out the Scaladoc for Table
for the constructors:
new Table(_tableTag: Tag, _tableName: String)
new Table(_tableTag: Tag, _schemaName: Option[String], _tableName: String)
The compiler is telling you that you have those choices but are using neither. You construct your instance of Table
called Resources
with just a String
. As you can see, that isn't an option. No pun intended.
The documentation shows that your declaration should look more like this:
class Resources(tag: Tag) extends Table[(Long, UserId, String)](tag, "RESOURCE") {
...
}
val Resources = TableQuery[Resources]
Upvotes: 1