【发布时间】:2018-02-25 20:29:41
【问题描述】:
我想更新一个表,但需要根据某些条件选择行。以下代码编译正常,但抛出运行时异常:
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[SlickException: A query for an UPDATE statement must resolve to a comprehension with a single table -- Unsupported shape: Comprehension s2, Some(Apply Function =), None, ConstArray(), None, None, None, None]]
这里是函数(目的是只允许合格用户更新):
def updateRecord(record: Record)(implicit loggedInUserId: User) = {
val q = records.withFilter(_.id === record.id).join(companies).on(_.companyId === _.id).filter(_._2.userid === loggedInUserId)
val recordToUpdate = q.map { case (r, c) => r }
val action = for {
c <- recordToUpdate.update(record)
} yield (c)
... // there are other actions in the for comprehension, removed them for clarity
我认为映射的结果是记录表中的一行(不是元组),但错误似乎表明我没有更新“单个”表。
或者有没有更好的查询+更新方式?
【问题讨论】: