是否可以在命名查询中访问对象的属性?
这是一个示例域类
class Publication {
String title
String author
Date datePublished
Integer numberOfPages
static namedQueries = {
newerPublications {
//Will throw an error, cannot access a variable declared in a dynamic context.
gt 'datePublished', this.datePublished
}
}
}
答案 0 :(得分:1)
您可以这样做:
newerPublications { Publication newerThan ->
gt 'datePublished', newerThan.datePublished
}
然后您将其称为Publication.newerPublications(referencePublication).list()