tags:

views:

176

answers:

1

I have a relationship like this:

class E {
  string name
  hasMany = [me:ME]
}

class M {
  float price
}

class ME {
 E e
 M m
 int quantity
}

And I'd hate to iterate to achieve this: "obtain the sum of the quantity in ME times the price of the corresponding M for a given E".

Any hints on how to implement it using GORM/HQL ?

Thanks in advance

+1  A: 

Haven't tested this, but it should be close if it doesn't work out of the box:

def givenE = // the E we're looking for
def sum = ME.executeQuery("select sum(m.price) from ME as me join me.m as m where me.e = :e", [e: givenE])
println sum
Ted Naleid