Grails/GORM 通过关系 ID 而不是关系对象本身获取域的动态查找器

Grails/GORM dynamic finder to get the domain by its relation ID instead of relation object itself

grails版本=3.2.9, gormVersion=6.0.10

比如说,我们有两个 grails 域:

class A {
   int id
   B b
}

class B {
   int id
}

现在,如果我的代码中有一些 B 的 ID(假设我在枚举中有该 ID),通过 [=14= 的 ID 获取 A 的实例] 使用 GORM 动态查找器的唯一方法如下:

A.findByB(B.get(bId))

这确实会导致额外的查询来获取 B 实例,这并不理想。

那么有没有什么办法,也许是一些 Grails/GORM 插件,添加对以下内容的支持:

A.findByBId(bId)

使用 A.findByB(B.load(bId)) 避免获取 B 对象。

http://docs.grails.org/latest/ref/Domain%20Classes/load.html