【发布时间】:2018-07-27 06:19:34
【问题描述】:
我有一个数据库表 InventoryLotUsage,其中包含列 id、inventoryLotId 和 date。我想删除一个 InventoryLot,但在执行此操作之前,我需要根据日期和其他一些条件更新具有外键 inventoryLotId 的 InventoryLotUsage 行。
我的问题是如何使用 monadic join 查询数据,对其进行一些计算并使用这些计算的结果在 Slick 的一个事务中运行更新?
我试图获得这样的一系列行
for {
il <- InventoryLot.filter(_.id === id)
lotUsage <- InventoryLotUsage.filter(_.inventoryLotId === id).result
groupedUsage = lotUsage.groupBy(_.date)
...
}
我的 IDE 建议 lotUsage 将是一个 Seq[InventoryLotUsageRows],但是在编译时由于 .result 而出现类型错误。
type mismatch;
found : slick.dbio.DBIOAction[FacilityProductRepository.this.InventoryLot,slick.dbio.NoStream,slick.dbio.Effect.Read with slick.dbio.Effect.Read with slick.dbio.Effect.Read]
required: slick.lifted.Query[?,?,?]
lotUsage <- InventoryLotUsage.filter(_.inventoryLotId === id).result
不使用 .result 它的类型是 InventoryLotUsage 表。如何将查询转换为可用于计算的内容?
【问题讨论】:
-
我想你忘记了
il <-线上的.result