[英]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.