Grails: How can I search through children in a hasMany relationship?

Posted by intargc on Stack Overflow See other posts from Stack Overflow or by intargc
Published on 2010-03-13T06:00:40Z Indexed on 2010/03/13 6:05 UTC
Read the original article Hit count: 210

Filed under:

If I have a Client domain class, and that Client hasMany Courses. How do I find the course I'm looking for? For instance:

class Client {
    String name
    static hasMany = [courses:Course]
}

class Course {
    String name
    static belongsTo = [client:Client]
}

def client = Client.get(1)

I want to "find" or "search" within that courses relationship. Maybe something like:

client.courses.find(name:'Whatever')

Is there any way to do this with Grails?

© Stack Overflow or respective owner

Related posts about grails