Pregunta

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"
}
¿Fue útil?

Solución

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
    )
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top