【问题标题】:Grails Eager fetching an empty association returns nullGrails Eager 获取空关联返回 null
【发布时间】:2012-10-15 08:38:16
【问题描述】:

我有如下领域类

Class Author{
String name 

List books = LazyList.decorate(new ArrayList(), FactoryUtils.instantiateFactory(Book.class)


static hasMany = [books:Book]

}

Class Book {
String title
static belongsTo = [author:Author]

}

现在我正在尝试获取作者

Author authorInstance = Author.find("from Author a inner join fetch a.books where a.id =:authorid",[authorid:Long.parseLong(params.id)]

现在,当该作者没有任何书籍时,即书籍关联为空 authorInstance 返回为空

我不确定,但我认为这是因为lazyList(我使用lazyList的原因是为了更容易数据绑定)。

【问题讨论】:

    标签: grails one-to-many eager empty-list


    【解决方案1】:

    发现问题在于内连接,当关联为空时内连接显然不会返回任何内容,所以我将其更改为左外连接,它开始工作

    【讨论】:

      猜你喜欢
      • 2022-06-13
      • 2021-01-31
      • 2017-11-06
      • 2015-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-18
      • 2015-12-28
      相关资源
      最近更新 更多