简体   繁体   English

Grails 3.2-通过分页和一对多关联进行选择

[英]Grails 3.2 - Select with pagination and one-to-many association

Grails 3.2 comes with some major updates to GORM. Grails 3.2对GORM进行了一些重大更新。 How would one do a query like: 如何执行查询:

def c = Cat.createCriteria()
List<Cat> data = c.listDistinct(){
    createAlias('furType', 'ft)
    createAlias('kittens', 'kitten')
    createAlias('kitten.furType', 'kft')
    or {
        ilike('ft.color', 'orange')
        ilike('kft.color', 'orange')
    }
    maxResults 10
    firstResult 10
}

Currently this query only shows 5 results instead of 10 when each cat has two kittens. 当前,当每只猫有两只小猫时,此查询仅显示5个结果,而不是10个结果。

Edit: Edited example to show how duplicate Cats can get called. 编辑:编辑后的示例显示如何调用重复的猫。

Try this. 尝试这个。

def c = Cat.createCriteria()
List<Cat> data = c.listDistinct(max: 10, offset: 10){
    createAlias('kittens', 'kitten')
    createAlias('kitten.furType', 'kft')
    ilike('kft.color', 'orange')
}

A better way, if you are paginating by creating links, you can create links in the following format 更好的方法是,如果要通过创建链接进行分页,则可以按以下格式创建链接

http://example.com/controller/action?offset=10

and then in your controller action, you can do the following 然后在控制器操作中,您可以执行以下操作

params.max = 10
def c = Cat.createCriteria()
List<Cat> data = c.listDistinct(params){
    createAlias('kittens', 'kitten')
    createAlias('kitten.furType', 'kft')
    ilike('kft.color', 'orange')
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM