【发布时间】:2018-03-27 07:59:27
【问题描述】:
给定以下 Slick 代码:
val doUpdate = true
val table1 = TableQuery[Table1DB]
val table2 = TableQuery[Table2DB]
val table3 = TableQuery[Table3DB]
val action = (for {
_ <- table1.filter(_.id === id).update(table1Record)
_ <- table2.filter(_.id === id).update(table2Record)
_ <- table3.filter(_.id === id).update(table3Record)
} yield ()).transactionally
只有当变量 doUpdate 为真时,我才需要更新 table2 和 table3。这是我的尝试:
val action = (for {
_ <- table1.filter(_.id === id).update(table1Record)
_ <- table2.filter(_.id === id).update(table2Record)
if (doUpdate == true)
_ <- table3.filter(_.id === id).update(table3Record)
if (doUpdate == true)
} yield ()).transactionally
这可以编译,但是当我运行它时,我收到以下错误Action.withFilter failed。如何添加条件?
【问题讨论】: