我正在尝试使用 Squeryl(scala 2.8.1 为 0.9.4)动态查询(.?
和inhibitWhen(...)
)。当我使用 String/Int/whatever 字段时,它们工作正常,但似乎干扰了 squeryl 用于布尔条件的语法糖。
假设我们在is_trusted: Option[Boolean]
某处定义了以下代码
where ( obj =>
obj.is_trusted === is_trusted.?
)
不编译,抛出以下错误:
... type mismatch;
[error] found : org.squeryl.dsl.ast.LogicalBoolean
[error] required: org.squeryl.dsl.NonNumericalExpression[org.squeryl.PrimitiveTypeMode.BooleanType]
[error] obj.is_trusted === is_trusted.?
[error] ^
即使这个也不起作用,在第一个条件下失败:
where ( obj =>
obj.is_trusted.inhibitWhen(is_trusted == Some(true)) and
not(obj.is_trusted).inhibitWhen(is_trusted == Some(false))
)
唯一的工作版本使用 doublenot
作为编译器的提示:
not(not(obj.is_trusted)).inhibitWhen(is_trusted != Some(true)) and
not(obj.is_trusted).inhibitWhen(is_trusted != Some(false))
有没有更理智的方法来使用布尔值进行动态查询?