0
2域類,人與屬性GORM個createCriteria() 「和」 問題
class Person {
static hasMany = [attributes : Attribute]
}
class Attribute{
String key
String value
}
查詢FNAME:
def c = Person.createCriteria()
def result = c.list{
attributes {
eq("key", "fname")
eq("value", "foo")
}
println result
}
結果: [富富 ,富巴]
查詢lname:
def c = Person.createCriteria()
def result = c.list{
attributes {
eq("key", "lname")
eq("value", "bar")
}
println result
}
結果: [巴巴 ,FOO巴]
查詢L-NAME OR FNAME:
def c = Person.createCriteria()
def result = c.list{
or{
attributes {
eq("key", "fname")
eq("value", "foo")
}
attributes {
eq("key", "lname")
eq("value", "bar")
}
}
println result
}
結果: [富FOO ,FOO酒吧 ,酒吧酒吧]
但如果我改變或並且,我沒有得到任何結果:
def c = Person.createCriteria()
def result = c.list{
and{
attributes {
eq("key", "fname")
eq("value", "foo")
}
attributes {
eq("key", "lname")
eq("value", "bar")
}
}
println result
}
結果: []