简体   繁体   English

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

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

grailsVersion=3.2.9, gormVersion=6.0.10 grailsVersion = 3.2.9,gormVersion = 6.0.10

Say, we have two grails domains: 假设我们有两个grails域:

class A {
   int id
   B b
}

class B {
   int id
}

Now, if I have an ID of some B in my code(say I have that ID in an enum), to get an instance of A by ID of B using GORM dynamic finder the only way is the following: 现在,如果我的代码中有一个B的ID(例如,我的枚举中有该ID),则要使用GORM动态查找器通过B的ID获得A的实例,唯一的方法是:

A.findByB(B.get(bId))

which does cause an additional query to get the B instance and that is not ideal. 这确实会导致额外的查询来获取B实例,这并不理想。

So is there any way, maybe some Grails/GORM plugin, adding a support for the following: 所以有什么办法,也许是一些Grails / GORM插件,添加了对以下内容的支持:

A.findByBId(bId)

Use A.findByB(B.load(bId)) to avoid fetching the B object. 使用A.findByB(B.load(bId))避免获取B对象。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM