views:

71

answers:

1

assuming the following example:
I have a User class and a Item class and a user can have many items

1) Is there a combined dynamic method to get all the items for a user and also sort them after a Property? I have a controller action that gets the items for a user and send them to the view, and the view will render them all with < g:each>. But I want to sort them by any property of Item without sorting the array after it is relived from GORM (using sort in controller or view). So basically what I do now is

items = Item.findAllByOwner(userInstance)
and then send the [items:items.sort{it.property}] to the view. I want to combine findAllBy with
Item.listOrderByProperty()

2) Assuming that there is such a method as on 1) : I want to use it to escape the overhead of sorting the array after constructing it. Will such a method be more performant instead of making a sort{} on items ?

+4  A: 

You can pass a map of options to findAllBy. Take a look at http://www.grails.org/doc/1.2.2/ref/Domain%20Classes/findAllBy.html .

John Stoneham
Yeah, I just found that. It now looks like a stupid question - but thanks for the good answer.
cripox