Question

I have a one to many relationship I need to list all parents only if it has children.

I tried a criteria like this but it did not work

def c = One.createCriteria()
def results = c.list {
  isNotNull "manies"
}
Was it helpful?

Solution

Use the newer where syntax:

One.findAll {
    manies.size() > 0    
}

This will create a query like:

from
    One this_ 
where
    ? < (
        select
            count(*) 
        from
            Many 
        where
            this_.id=one_id
    )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top