gpt4 book ai didi

grails - 子查询联接两个级别的父表的命名查询

转载 作者:行者123 更新时间:2023-12-02 16:01:06 25 4
gpt4 key购买 nike

给定

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()

No signature of method: namedboom.Store.call() is applicable for argument types: (namedboom.Product$__clinit__closure1$_closure3$_closure4$_closure5) values: [namedboom.Product$__clinit__closure1$_closure3$_closure4$_closure5@768aab6a] Possible solutions: wait(), last(), save(), any(), getAll(), wait(long)



用命名查询完成此操作的正确方法是什么?我可以使其正常工作的唯一方法是使用createCriteria并声明父表的联接。

最佳答案

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

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

关于grails - 子查询联接两个级别的父表的命名查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30724807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com