我正尝试在grails中使用创建条件方法,但是我得到了一个空列表,我不知道为什么。我的代码如下
def results = PostOrder.createCriteria().list() {
posts{
author{
eq('username', lookupPerson().username)
}
}
picture{
user{
eq('username', lookupPerson().username)
}
}
}PostOrder域名如下:
class PostOrder {
String pOrder
Date dateCreated
Picture picture
Post posts
Video video
Boolean favorite = false
static hasMany = [children : Child]
static constraints = {
picture nullable: true
posts nullable: true
video nullable: true
}
}帖子如下:
class Post {
String message
User author
Date dateCreated
Child child
boolean postedToAll
String tag
static hasMany = [tags:Tag]
static constraints = {
child nullable: true
tags nullable: true
tag nullable: true
}
}最后的图片如下所示:
class Picture {
String orgName
String urlOrg
String urlWeb
String urlThumb
Date dateCreated
String caption
Child child
User user
Album contained
String tag
boolean postedToAll
static hasMany = [tags:Tag]
static constraints = {
orgName blank: false
caption maxSize: 500
tags nullable: true
caption nullable: true
tag nullable: true
child nullable: true
}
}对我来说,这可以很好地工作,有谁知道为什么不是这样吗?
发布于 2015-11-12 14:15:12
它在图片和帖子中都有相同的用户名吗?如果不是,则必须用和或{}将它们括起来,因为默认情况下使用的是逻辑和
发布于 2016-08-02 02:27:33
也许您应该添加一个逻辑块(和/或),如下所示:
def results = PostOrder.createCriteria().list() {
or {
posts{
author{
eq('username', lookupPerson().username)
}
}
picture{
user{
eq('username', lookupPerson().username)
}
}
}
}https://stackoverflow.com/questions/15899073
复制相似问题