I have a domain which call party and has many invitees. party.invitees give me a the set collection of the invitees. I want to get only some of the invitees so I try do do the followinf in my service.
partInvitees= event?.invitees?.findAll{[offset: 3,max: 8]}
It doesn't give the correct result. It gives me all the invitees instead only the specific I have asked.
The
findAllmethod you are invoking in there is not from GORM, but from Groovy Collections. So even if you paginate it (which is not possible directly in Groovy, AFAIK), you'll be bringing the whole collection into memory. If you don't mind, just do:event?.invitees[offset..(offset-1)+max]If the collection is too big and you don't want to bring it to memory, you can also query the
Inviteedirectly:Invitee.findAllByEvent(event, [offset: 3,max: 8])But be aware that the order won't be necessarily the same, since Gorms'
findAllBydoesn't know about the collection index (I'm assuminginviteesis a list). You can make the collection index-aware, but it's a bit tricky.