鉴于
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]
}
我收到错误:
def store = Store.first() // just for the sake of testing
Product.productsInStockByStore(store).list()
没有方法签名:namedboom.Store.call()适用于 参数类型: (namedboom.Product $ __ clinit__closure1 $ _closure3 $ _closure4 $ _closure5) 值: [namedboom.Product$__clinit__closure1$_closure3$_closure4$_closure5@768aab6a] 可能的解决方案:wait(),last(),save(),any(),getAll(), 等待(长)
使用命名查询完成此操作的正确方法是什么?我能让它工作的唯一方法是使用createCriteria并为父表声明关节。
答案 0 :(得分:0)
这可能是因为您的命名查询中定义了store
。尝试在命名查询中更改此变量的名称,例如
static namedQueries = {
productsInStockByStore {storeInstance->
department {
store {
eq 'id', storeInstance.id
}
}
gt 'qty', 0
}
}