【问题标题】:Grails/GORM dynamic finder to get the domain by its relation ID instead of relation object itselfGrails/GORM 动态查找器通过其关系 ID 而不是关系对象本身获取域
【发布时间】:2019-07-06 00:27:45
【问题描述】:

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)

【问题讨论】:

    标签: java hibernate grails relational-database grails-orm


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2010-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多