I have a User class that hasMany = [friends:User]
Now I am trying to display the friends list – ${user.friends}
However, I’d like to be able to apply parameters like I can with, for example, User.findAllBy(user, [max:10, sort: ‘dateCreated’, order: ‘desc”])
Can someone kindly tell me how to do this on a one-to-many in Grails / Groovy ?
I’d use HQL:
You could try to filter the friends collection, but as soon as you do anything with it it’ll get fully loaded from the database, so if you only want 10 instances you’ll have wasted loading all of the rest.