簡體   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

假設我們有兩個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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM