Grails 具有动态参数的Gorm查找器(第2部分)?

Grails 具有动态参数的Gorm查找器(第2部分)?,grails,groovy,Grails,Groovy,我有以下域类: class AccountRecord { List owners // owner of this account } 及 AccountRecord类中的所有者列表通过存储包含每个所有者的uniqueId和secondaryId对的映射来存储该帐户的所有所有者。因此,所有者列表可能如下所示: [ [uniqueId: 1, secondaryId 2] // owner 1 [uniqueId: 2, secondaryId 3] // owner 2 ] 假

我有以下域类:

class AccountRecord {
     List owners // owner of this account
}

AccountRecord
类中的
所有者列表
通过存储包含每个所有者的uniqueId和secondaryId对的映射来存储该帐户的所有所有者。因此,所有者列表可能如下所示:

[
[uniqueId: 1, secondaryId 2] // owner 1 
[uniqueId: 2, secondaryId 3] // owner 2
]
假设我想使用GORM查找其所有者列表包含映射的所有
AccountRecord
,这样映射就包含了给定的IndividualRecord的uniqueId和secondaryId。基本上,给定一个人,查找该个人拥有的所有帐户。目前,我正在这样做,但它不起作用(由于某种原因,它还返回非个人所有的帐户):


有什么建议吗?

如果没有特别的理由不使用标准gorm:N关系,您可以这样实现它:

class AccountRecord {
  static hasMany = [owners: IndividualRecord]
}

class IndividualRecord {

  String uniqueId
  String secundaryId

  static belongsTo = AccountRecord
  static hasMany = [accounts: AccountRecord]
}
基本上,给定一个人,查找该个人拥有的所有帐户


这可以通过使用以下关联轻松实现:
myIndividual.accounts

谢谢。如果不使用关联,您能建议如何执行吗?谢谢。
def accountsOwnedByUser = AccountRecord.where {[uniqueId: someOwner.uniqueId, secondaryId: someOwner.secondaryId] in owners}.list()
class AccountRecord {
  static hasMany = [owners: IndividualRecord]
}

class IndividualRecord {

  String uniqueId
  String secundaryId

  static belongsTo = AccountRecord
  static hasMany = [accounts: AccountRecord]
}