Search code examples
grailsgroovygrails-orm

Collecting values from a list of objects in groovy


I have a method like this

static getList (long colorid) {
     ColorShades.findAll 'from ColorShades where color.id = :colorid', [colorid: colorid]
}

I'm using it like this:

def shadeIdsForAColor = ColorShades.getList(colorid as long)

Question

The method returns an ArrayList of ColorShade objects and each object has a shadeId with it.

What can I do to put those ids as a list of integers into the shadeIdsForAColor variable?


Solution

  • Doesn't this do it?

    def shadeIdsForAColor = ColorShades.getList(colorid as long).shadeId