tags:

views:

179

answers:

2
class Address {
    static hasMany = [addressGroups: AddressGroup]
    ...
}

class AddressGroup {
    static belongsTo = Address
    static hasMany = [addresses: Address]

    String notation;
    ...
}

I try to fetch all Addresses for a given AddressGroup.

My code:

def params = [max: 10]
def addressGroup = AddressGroup.findByNotation("asdf")
def addresses = Address.findAllByAddressGroups(addressGroup, params)

The error message: No value specified for parameter 2

The logged SQL statement:

select ... from ADDRESSES this_ where this_.id=10 order by this_.id asc limit ** NOT SPECIFIED **

... which is completly wrong.

Any ideas?

I could fetch the Addresses by using addressGroup.addresses (and that works!), but I want to display it in a table with pagination so i need to max / offset params.

+1  A: 

I don't think the dynamic finders take the pagination parameters you need.

Check out GORM Labs Plugin, which introduces some extensions to GORM. Section "Paginated HasMany Properties" shows you how to do what you are looking for.

Jean Barmash
looks like the way to go ... thanks!
arturh
A: 

Well ... I tried using the GORM extension, but after looking at it a bit closer I saw it has not what i need.

I endet up using the Criteria API:

def c = Address.createCriteria()
def results = c.list {
   if(params.addressGroup) {
      addressGroups {
         eq('id', params.addressGroup)
      }
   }

   maxResults(params.max)
   order(params.sort, params.order)    
}
arturh