2012-08-02 23 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) 
     } 
    }) 
}