开发者

Grails: Is there a way to have findAll() without a query but with pagination and sorting?

As I noticed in the answers of another question there are a few problems when testing finder methods in GORM.

I want to get all objects from Something and have support for sorting and pagination, so I wrote this:

SomethingListVO findAllSomethings(int offset = 0, int limit = 50) {
    def somethingCount = Something.count()
    def somethings = Something.findAll([max: limit,
                                            offset:offset,
                                            sort: "number",
                                            or开发者_StackOverflow中文版der: "asc"])
    return new SomethingListVO(somethingCount,somethings)
}

This can't work because if you want to add something like pagination or sorting you need to have a query. But if you add a query like SELECT * FROM Something your test will fail.

Is there any way to test this method (with pagination/sorting)?

This approach seems to provide more features but it won't work with my grails installation.


Just do this for your query

Something.list([max: limit,offset:offset,sort: "number",order: "asc"])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜