1

我正在尝试使用 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))

有没有更理智的方法来使用布尔值进行动态查询?

4

1 回答 1

1

嗯...我认为这可能是另一个由 Boolean -> LogicalBoolean 的隐式转换引起的错误。由于与此类似的问题,该功能已在 0.9.5 中弃用。什么.? 应该做的是从 Boolean -> BooleanExpression 触发隐式转换,但由于 LogicalBoolean 有一个 .? 方法也存在冲突,后者似乎具有优先权。我知道它不是非常漂亮,但试试这个:

where ( obj => 
  obj.is_trusted === is_trusted.~.?
)

.~ 应该在 .? 之前强制转换为 BooleanExpression[Option[Boolean]] 被调用。

于 2011-10-03T20:59:30.097 回答