2012-08-02 17 views
1

查询“与”声音上激活框架简单,“”让‘与’工作使用或在激活的框架查询

transactional { 
    val personList2 = allWhere[NaturalPerson](_.name :== "Test", _.motherName :== "Mother") 
} 

我不知道如何或制成。一个例子会很好。

回答

1

您可以在allWhere中使用OR。请注意,您必须使用括号。

allWhere[NaturalPerson](p => (p.name :== "Test") :|| (p.motherName :== "Mother")) 

或者你可以使用完整的查询方式:

query { 
    (p: NaturalPerson) => where((p.name :== "Test") :|| (p.motherName :== "Mother")) select(p) 
} 
2

看看框架附带的测试套件。下面是一个从QuerySpecs.scala取得的示例测试:

"support query with or" in { 
    activateTest(
    (step: StepExecutor) => { 
     import step.ctx._ 
     step { 
     newFullActivateTestEntity 
     newEmptyActivateTestEntity 
     } 
     step { 
     query { 
      (e: ActivateTestEntity) => 
      where( (e.booleanValue :== true) 
        :|| (e.booleanValue :== false) 
        :|| (e.booleanValue isNull)) select (e) 
     }.size must beEqualTo(3) 

     query { 
      (e: ActivateTestEntity) => 
      where( (e.booleanValue :== true) 
        :|| (e.charValue :== fullCharValue)) select (e) 
     }.size must beEqualTo(1) 
     } 
    }) 
}