我正在尝试使用可选的参数过滤表。使用光滑的2.1这有效,但当我转到3.0版本不再有效时,错误是:"无法解析符号&&"当我调用函数" reduce"。
我将不胜感激任何帮助..非常感谢
这是代码:
def getAll(params : ClienteSearchParameters) : DBIOAction[Iterable[Cliente], NoStream, Effect.Read] = {
val q = for {
(x, (y, z)) <- tabla join (tablaPersonas joinLeft tablaContactos on (_.id === _.idPersona)) on (_.idPersona === _._1.id)
if {
List(
params.nombre.map(y.nombre === _),
params.apellido.map(y.apellido === _),
params.fechaAlta.map(x.fechaAlta === _),
params.fechaRegistracion.map(x.fechaRegistracion === _)
).flatten match {
case Nil => LiteralColumn[Boolean](true)
case seq => seq.reduce(_ && _)
}
}
} yield (x, y, z)
答案 0 :(得分:0)
以下是来自文档http://slick.typesafe.com/doc/3.0.0/queries.html#sorting-and-filtering
的信息我想你可以在这里找到你想要的东西。来自doc的例子:
//building criteria using a "dynamic filter" e.g. from a webform.
val criteriaColombian = Option("Colombian")
val criteriaEspresso = Option("Espresso")
val criteriaRoast:Option[String] = None
val q4 = coffees.filter { coffee =>
List(
criteriaColombian.map(coffee.name === _),
criteriaEspresso.map(coffee.name === _),
criteriaRoast.map(coffee.name === _) // not a condition as `criteriaRoast` evaluates to `None`
).collect({case Some(criteria) => criteria}).reduceLeftOption(_ || _).getOrElse(true:Column[Boolean])
}