0

我正在尝试在 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
    }
}

对我来说,这会很好用,任何人都可以看到为什么不可以吗?

4

2 回答 2

0

也许您应该像这样添加一个逻辑块(和/或):

def results = PostOrder.createCriteria().list() {
    or {
        posts{
            author{
                eq('username', lookupPerson().username)
            }
        }
        picture{
            user{
                eq('username', lookupPerson().username)
            }
        }
    }
}
于 2016-08-01T18:27:32.520 回答
0

图片和帖子中的用户名是否相同???如果不是,则必须用 and or{} 将它们括起来,因为默认情况下它使用 and 逻辑

于 2015-11-12T06:15:11.693 回答