我尝试使用Squeryl (对于Scala2.8.1,是0.9.4)动态查询(.?和inhibitWhen(...))。当我使用String/Int/任何字段时,它们工作得很好,但似乎干扰了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))
)唯一可用的版本使用double not作为编译器的提示:
not(not(obj.is_trusted)).inhibitWhen(is_trusted != Some(true)) and
not(obj.is_trusted).inhibitWhen(is_trusted != Some(false))有没有一种更明智的使用布尔值进行动态查询的方法?
发布于 2011-10-04 04:59:30
嗯..。我认为这可能是从布尔-> LogicalBoolean隐式转换导致的另一个错误。由于类似的问题,该功能在0.9.5中已被弃用。怎么回事?应该做的是从布尔-> BooleanExpression触发隐式转换,但因为LogicalBoolean有.?方法也存在冲突,而后者似乎具有优先权。我知道它不是很漂亮,但是试试这个:
where ( obj =>
obj.is_trusted === is_trusted.~.?
)在此之前,.~应强制转换为BooleanExpression[OptionBoolean]。将被调用。
https://stackoverflow.com/questions/7607449
复制相似问题