寻找嵌套对象存在

时间:2016-08-17 10:49:25

标签: grails

class Car {
    String carname
}

class Factory {
    Car car
    String factoryname
}

如何查看Factoryfactoryname == "Kia"的对象carname == "newmodel"是否存在?

1 个答案:

答案 0 :(得分:2)

您可以使用 createCriteria()方法和别名

def cName = 'newmodel'
def fName = 'Kia'
def objects = Factory.createCriteria().count() {
    createAlias('car', 'c'),
    eq('c.carname', cName)
    eq('factoryname', fName)
}
boolean isThere = objects