Grails hasMany列上的gorm过滤器

Grails hasMany列上的gorm过滤器,grails,subquery,gorm,Grails,Subquery,Gorm,我有2个域名类,如下所示: class Customer { def name static hasMany = [accounts:Account] } class Account { def accountNo def type } 此处帐户的类型可以是“保存”、“当前”和“FD” 我想写一个条件来搜索所有帐户类型为“储蓄”、“当前”的客户 我尝试使用以下标准: def customers = Customer.createCriteria().list {

我有2个域名类,如下所示:

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。

您可以使用或代替Y.Tarion建议的或在中使用:

您可以使用或代替Y.Tarion的建议或在以下情况下使用:


如果使用或代替和会发生什么情况?因为我想得到所有拥有两种类型帐户的客户如果使用或代替和会发生什么情况?因为我想得到所有拥有两种类型帐户的客户。实际上,此查询返回拥有类型储蓄或活期存款的客户,但实际上我想要至少拥有这两种类型帐户的客户账户类型他们可能有两种以上的账户,比如储蓄,活期或储蓄,活期,FD等等。事实上,这有点复杂,我不确定你是否能用标准做到这一点。SQL看起来像:select*from customer where id in select customer\U accounts\U id in customer\U account\U id=1和select customer\U accounts\U id in customer\U id in customer\U account\U id in customer\U id in CUSTOMENTER\U account\U id=2请参见:我尝试了以下方法,但没有生成适当的输出:def results        帐户{          '在'id'中,新的DetachedCriteriaAccount.build{            投影{              属性'customer.id'            }             eq‘类型’,它          }           }实际上,这个查询返回的客户要么是储蓄型的,要么是活期的,但实际上我想要的客户至少有两种类型的账户,他们可能有两种以上的账户,比如储蓄、活期或储蓄、活期、FD等。好的,现在我找到你了。事实上这有点复杂,我不确定你是否能做到这一点SQL看起来像:select*from customer where id in select customer\U accounts\U id from customer\U account\U id=1和select customer\U accounts\U id from customer\U account\U id in customer\U id=2请参见:我尝试了以下方法,但没有生成适当的输出:def results=customer.withCriteria{        帐户{          '在'id'中,新的DetachedCriteriaAccount.build{            投影{              属性'customer.id'            }             eq‘类型’,它          }           }
def types = ["Savings", "Current"]
def customers = Customer.createCriteria().list {
    accounts {
        "in" "type", types
    }
}