Pablo Mosby
Pablo Mosby

Reputation: 319

Grails 1 to n relation find by Children

I have this two classes:

class Father{
  static hasMany= [children:Child]
}

class Child{
  String name
}

and In my controller I need to find if there is any father with an specific child but this does not work, asks for a set of children:

Father.countByChildren(Child.get(1))

Any suggest?

Thanks

Upvotes: 1

Views: 54

Answers (1)

Taras Kohut
Taras Kohut

Reputation: 2555

You can use Criteria:

Father.createCriteria().count {
        children {
            idEq(1L)
        }
    }

Upvotes: 2

Related Questions