Pablo Alba
Pablo Alba

Reputation: 131

Grails criteria select when hasMany hasn't any elements

I have the classes:

class Course{
   String name
   static hasMany = [
        studentGrades: StudentGrade
    ]
}

class StudentGrade{
    String name
    int grade
}

How can I make a criteria to get the courses without any student grade?

Upvotes: 1

Views: 891

Answers (1)

aiolos
aiolos

Reputation: 4697

You could use the isEmpty criterion method:

def c = Course.createCriteria()
def results = c.list {
    isEmpty("studentGrades")
}

See the docs for further informations.

Upvotes: 2

Related Questions