Jils
Jils

Reputation: 783

grails use offset/max and pagination with getAll?

I have a list of integer representing ids.

I want to use getAll to retreive and return all instances to GSP and I would like also to use pagination (offset, max).

How can I do that

MyClass.getAll([1, 2, 3,...])

Thank you for your help

Upvotes: 0

Views: 421

Answers (2)

Dan Vega
Dan Vega

Reputation: 1107

As dmahapatro pointed out you can also use executeQuery. This gives you a lot of control of the query to run and the params to pass in.

def users = User.executeQuery("from User u where u.id IN (1,2,3)",[max:2,offset:0])

Upvotes: 1

dmahapatro
dmahapatro

Reputation: 50255

You can use findAllBy* or drill down using an HQL with executeQuery. I think the former approach will be simpler since only ids are involved.

MyClass.findAllByIdInList([1, 2, 3, ....]*.toLong(), [max: 5, offset: 1])

Upvotes: 3

Related Questions