firnnauriel
firnnauriel

Reputation: 2063

How to set offset in GORM when using createCriteria?

I'm just wondering if it's possible for 'createCriteria' to specify the paginateParams (i.e. offset) similar to dynamic finder (findAll, etc.)

Note that this code is not working since 'offset' is not documented in http://www.grails.org/doc/1.2.1/ref/Domain%20Classes/createCriteria.html

def c = SnbrItemActDistance.createCriteria()
def results = c.list {
    eq('iid', newsId)
    ge('distance', cap)

    maxResults(count)
    offset(offset)
    order('distance', 'desc')
}

Upvotes: 3

Views: 5055

Answers (2)

leebutts
leebutts

Reputation: 4882

You can also pass in a map to list e.g.

def c = SnbrItemActDistance.createCriteria()
def results = c.list(max:count, offset:offset) {
    eq('iid', newsId)
    ge('distance', cap)
}

Upvotes: 2

ig0774
ig0774

Reputation: 41277

I believe you'd want to use something like:

...
firstResult(offset)
...

As I recall, the Criteria DSL corresponds closely to the Hibernate Criteria class.

Upvotes: 7

Related Questions