开发者

Error while Querying a many-to-many relationship in Grails

class Addr开发者_JAVA百科ess {
    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.


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.


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)    
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜