假设您有三个域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'的语法错误???
答案 0 :(得分:2)
您的查询的标准似乎有点误导。 books
和words
都是关联,您希望words
等于word
对象的单个实例。
你可以试试这个:
def getAuthors() {
Author.where {
books{
words {
id == this.id
}
}
}.list()
}