Sort based on column in child table using GORM?

grails, grails-orm

Solution

Try using a criteria query like so...

def c = Employee.createCriteria()
def results = c.list (max: maxRecords, offset: 100) {
    eq("name", name)
    address {
        order("addres1", "desc")
    }

}

This works for me!

Another option is to add a default sort order like so...

class Address{
    …
    static mapping = {
        sort address1:"desc"
    }
}

However, I always prefer to do things as an 'as-needed' basis rather than define that sorting be done every time even when it may not be needed. U pick. Enjoy!

Problem

I have a table called employee and child table address. Now I want to get a list of employees sort by address1 in address table using GORM. ``` Employee.findAllByName(name, [max: maxRecords, offset: 100,sort: Address.address1, order: desc]) ``` the above statement is not working, any suggestions would be appreciated. Thanks

Original source