gpt4 book ai didi

grails - 具有多个多对多关联的GORM 'where criteria'

转载 作者:行者123 更新时间:2023-12-02 14:33:29 24 4
gpt4 key购买 nike

假设您具有三个这样定义的域obj:

class Author {
String name
static hasMany = [books: Book]
}

class Book {
String name
static belongsTo = [author: Author]
static hasMany = [words: Word]
}

class Word {
String text

Set<Author> getAuthors() {
// This throws GenericJDBCException:
Author.where {
books.words == this
}
}
}

为什么 getAuthors()不能通过 ERROR spi.SqlExceptionHelper - Parameter "#1" is not set;失败,但是如果使用 Criteria重写则可以正常工作:
public Set<Author> getAuthors() {
// This works as expected:
Author.withCriteria {
books {
words {
eq('id', this.id)
}
}
}
}

我的“where query”语法错误吗???

最佳答案

您查询的条件似乎有点误导。 bookswords都是关联,您期望words等于word对象的单个实例。

您可以尝试以下方法:

def getAuthors() {
Author.where {
books{
words {
id == this.id
}
}
}.list()
}

关于grails - 具有多个多对多关联的GORM 'where criteria',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20204438/

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