我有2个domainClasses,如下所示:
class Customer {
def name
static hasMany = [accounts:Account]
}
class Account {
def accountNo
def type
}
这里的帐户类型可以是“保存”,“当前”,“FD”
我想编写一个条件来搜索所有帐户类型为“保存”,“当前”的客户。
我应该在以下条件下尝试使用什么标准:
def customers = Customer.createCriteria().list {
accounts {
and {
eq('type','Saving')
eq('type','Current')
}
}
}
但是,当它执行时,会创建内部连接,结果为0。
最佳答案
您可以使用or
代替Y. Tarion建议的and
,也可以使用in
:
def types = ["Savings", "Current"]
def customers = Customer.createCriteria().list {
accounts {
"in" "type", types
}
}
关于grails - hasMany列上的gorm过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42247395/