views:

42

answers:

1

I have these classes.

class Author{
    Person person
}


class Person{
    String lastName
    String firstName
    String middleName
}

I'd like to query Person and Author.

def persons = Person.findAllByLastNameiLike("${a}")

but it seems I can't do

def authors = Author.findAllByPerson(persons)

Any ideas how I'd do this?

+2  A: 

This code shown above does not work

def authors = Author.findAllByPerson(persons)

because findAllBy* works with a single object, not a collection. To find all authors where the Person is any one of those contained in persons use either HQL or a criteria query. For example an (untested) HQL query would look something like:

Author.executeQuery("""
    FROM Author a
    WHERE a.person IN (:people)""", [people: persons])
Don
Thanks did something similar.
Neoryder