How to compare collection item using createCriteria?

44 Views Asked by At

Registration domain has a collection of discounts.

static hasMany = [ discounts: Discount]

I want to extract all Registrations that have a particular discount applied.

In the following code i want to get all registrations whose collection has the discount of id disid. How can i achieve that? I appreciate any help!

def disid = Discount.get(1).id

def regs = Registration.createCriteria().list(){

            eq('compositeEvent', cod.compositeEvent)

}
1

There are 1 best solutions below

0
On

Try this:

def disid = Discount.get(1).id

def regs = Registration.withCriteria() {
    discounts  {
        eq 'id', disid
    }
}

See http://emmanuelrosa.com/articles/gorm-for-sqladdicts-where-clause/