关于 RestfulController 的 Grails 文档:嵌套资源查询包含 id == id

Grails documentation on RestfulController: nested resources query contains id == id

我正在使用 Grails RestfulController 并在文档第 9.1.5.1 节 (https://grails.github.io/grails-doc/latest/guide/single.html#extendingRestfulController) 中遇到了这个奇怪的查询,id == id:

@Override
protected Book queryForResource(Serializable id) {
    Book.where {
        id == id && author.id = params.authorId
    }.find()
}

一开始以为是doco的问题,实际写代码果然只对id == id有效。 Codenarc 还检测到奇怪的比较,并且生成的 Hibernate 查询符合预期。 谁能帮我理解一下?谢谢

 id   ==  id  
|___|    |___|
  |        |
  |        |
  |      id value passed as method parameter
  |
id property from domain class

where 查询或 DetachedCriteria 中表达式的左侧始终是来自域 class.

的 属性 的引用

类似于:

select a from Author as a where a.id = :id

其中 :id 将是传递给查询的参数