Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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",
                                            order: "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.

like image 566
hering Avatar asked Sep 21 '10 12:09

hering


1 Answers

Just do this for your query

Something.list([max: limit,offset:offset,sort: "number",order: "asc"])
like image 51
Aaron Saunders Avatar answered Nov 15 '22 20:11

Aaron Saunders