我正在编写一个用于更新模型用户的 dao;这是代码:
case class User(id: Option[String] = None, username: String, password: String)
object Users extends Table[User]("user") {
// .... some column defines
def * = id.? ~ username ~ password <>(User, User.unapply _)
def byId(id: String) = Query(Users).filter(_.id === id)
// user.id will be None since id is passed as parameter.
def update(id: String, user: User)(implicit session: Session) = {
byId(id).update(user)
getById(id)
}
我收到了这个错误:
[error] JdbcSQLException: NULL not allowed for column "id"; SQL statement:
[error] update "user" set "id" = ?, "username" = ?, "password" = ? where "user".
"id" = 'RBq0kJAs' [23502-168] (DbException.java:169)
似乎 Slick 生成了一条 SQL 语句来更新主列“id”,这没有任何意义。如何从生成的更新查询中删除 id 列?