简体   繁体   中英

Is there a default max to gorm list method on domain object in grails 3.2

For the life of me I cannot understand why in a controller that inherits from RestfulController, that the index method only returns 4 rows. Is this a default setting? The same behavior happens when I override the method, like so.

import grails.rest.*
import grails.converters.*

class WidgitController extends RestfulController {
    static responseFormats = ['json', 'xml']
    WidgitController() {
        super(Widgit)
    }

    @Override
    def index() {
        def w = Widgit.findAllWhere(isEnabled: true, [max: 10]) //w: sizec4
        def w2 = listAllResources(params) //w2: size 4
        respond w
    }
}

Any help would be appreciated.

Turns out the problem comes under better focus when you look up paging.

depending on how your domain objects are spec'd out gorm will us a different resultTransformer. In my case I had a one to many relationship that was spec'd as

orders(lazy:false, fetch:"join")

the fetch as join told gorm to do a large query and then reduce the set of data after the max offset was applied.

for more reading look into the following:

agination-with-hibernate-criteria-and-distinct-root-entity

sorting-and-pagination-with-hibernate-criteria-how-it-can-go-wrong-with-joins

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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