如何在trait中找到scala对象
我使用slick 1.0.1版本进行播放,这是我的代码: User.scala:如何在trait中找到scala对象,scala,playframework-2.0,slick,Scala,Playframework 2.0,Slick,我使用slick 1.0.1版本进行播放,这是我的代码: User.scala: case class User(id: Option[Int], name : String) trait UserComponent { this: Profile => import profile.simple._ object Users extends Table[User]("users") { def id = column[Int]("id", O.PrimaryKey) def name
case class User(id: Option[Int], name : String)
trait UserComponent {
this: Profile =>
import profile.simple._
object Users extends Table[User]("users") {
def id = column[Int]("id", O.PrimaryKey)
def name = column[String]("name", O.NotNull)
def * = id.? ~ name <> (User, User.unapply _)
def add(user: User)(implicit session: Session) = {
this.insert(user)
}
def countByName(name: String)(implicit session: Session) = {
(for {
user <- Users
if (user.name === name)
} yield(user)).list.size
}
}
}
错误是:
[error] F:\mysource\play-slick\app\models\Resource.scala:14: not found: value Us
erComponent
[error] def withuser = foreignKey("User_FK", owner, UserComponent.Users)(_.id)
[error] ^ ^
试一试
[error] F:\mysource\play-slick\app\models\Resource.scala:14: not found: value Us
erComponent
[error] def withuser = foreignKey("User_FK", owner, UserComponent.Users)(_.id)
[error] ^ ^
trait ResourceComponent {
this: Profile with UserComponent => // depend on the user component
object Resources extends Table[Resource]("RESOURCE") {
...
def withuser = foreignKey("User_FK", owner, Users)(_.id)
}
}