【发布时间】:2014-06-01 03:10:27
【问题描述】:
我定义了许多基本查询,并且正在使用查询组合来添加诸如排序、分页、where 子句等内容...
但我在访问 where 子句中连接的第二个表的字段时遇到问题...
这是我的表查询和我的表。所有表都映射到案例类。
val basicCars = TableQuery[CarTable]
val basicCarValues = TableQuery[CarValueTable]
val carsWithValues = for {
(c, v) <- basicCars leftJoin basicCarValues on (_.id === _.carId)
} yield (c, v.?)
现在我通过做一些事情来重用/组合查询,例如
carsWithValues.where(_._1.id === someId)
效果很好……
但如果我想访问第二张表的任何值......我会尝试
carsWithValues.where(_._2.latestPrice === somePrice)
它告诉我somePrice 不是MappedProjection 的成员......
错误:值 somePrice 不是 scala.slick.lifted.MappedProjection[Option[com......datastore.slick.generated.Tables.CarValue],(Option[Long], Option[Long] 的成员, 选项[字符串],.....
我知道这种方法行不通,因为 _._2 是 MappedProjection 而不仅仅是位于元组中的 CarValue..
但我不知道如何在 where 子句中使用 MappedProjection 中的表的任何字段?
【问题讨论】: