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))
)
not
唯一の動作バージョンは、コンパイラのヒントとしてdoubleを使用します。
not(not(obj.is_trusted)).inhibitWhen(is_trusted != Some(true)) and
not(obj.is_trusted).inhibitWhen(is_trusted != Some(false))
ブール値を使用して動的クエリを実行するためのより適切な方法はありますか?