Grails 连接两级父表的子表的命名查询

Grails 连接两级父表的子表的命名查询,grails,gorm,Grails,Gorm,给定 我在运行时遇到一个错误: class Store { String name static hasMany = [departments: Department] } class Department { String name static belongsTo = [store: Store] static hasMany = [products: Product] } class Product { String name

给定

我在运行时遇到一个错误:

class Store {
    String name

    static hasMany = [departments: Department]
}

class Department {

    String name

    static belongsTo = [store: Store]

    static hasMany = [products: Product]

}

class Product {
    String name
    Integer qty

    static namedQueries = {
        productsInStockByStore {store->
            department {
                store {
                    eq 'id', store.id
                }
            }
            gt 'qty', 0
        }
    }

    static belongsTo = [department: Department]

}
方法namedboom.Store.call()的签名不适用于 参数类型: (名称为boom.Product$\uuu clinit\uu closure1$\u closure3$\u closure4$\u closure5) 价值观: [namedboom.Product$\uuuu clinit\uuu closure1$\uClosure3$\uClosure4$_closure5@768aab6a] 可能的解决方案:wait()、last()、save()、any()、getAll(), 等待(长)


使用命名查询实现这一点的正确方法是什么?我能让它工作的唯一方法是使用createCriteria并为父表声明关节。

这可能是因为
存储
是在命名查询中定义的。尝试在命名查询中更改此变量的名称,如

def store = Store.first() // just for the sake of testing
Product.productsInStockByStore(store).list()

在这种情况下,还有一个问题。为什么我一小时前没问这个。。令人尴尬的谢谢
static namedQueries = {
    productsInStockByStore {storeInstance->
        department {
            store {
                eq 'id', storeInstance.id
            }
        }
        gt 'qty', 0
    }
}