[英]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
假設我們有兩個grails域:
class A {
int id
B b
}
class B {
int id
}
現在,如果我的代碼中有一個B
的ID(例如,我的枚舉中有該ID),則要使用GORM動態查找器通過B
的ID獲得A
的實例,唯一的方法是:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.