GORM paginateParams usage problem
I'm just trying to do pagination but until now I couldn't make it. I have 2 domain classes and one to many relationship.
class User {
static hasMany = [contacts:Contact]
}
class Contact {
static belongsTo = [ user : User ]
}
I have 20 Contacts.
When I tried to make a query like this :
def maxResult = 20
def startIndex = 0
def contacts = Contact.findAllByUser(user, [max:maxResult, offset:startIndex])
it is not working. Query is working but pagination with gorm is not working. Result is just 1 contact object.
when I tried;
def startIndex = 0
def contacts = Contact.findAllByUser(user, [offset:startIndex])
Result is 20 contact object but when i tried it with different startIndex value, it is not working also. for startIndex = 5, result is al开发者_开发百科so 20 ontact object.
Is there anybody have any idea about this. Maybe i am doing something wrong, maybe it is gorm's problem. I havent found the answer. Thanks for your answers.
I haven't tried the DynamicFinder to do this thing yet, but as I view the document, your syntax seems to be right. As an alternative, I use createCriteria to solve the paging problem.
def queryResult = Contact.createCriteria().list(max: max, offset: offset) {
and {
/// FILTER ///
user {
eq("id", userInstance.id)
}
}
}
精彩评论