Vitor Hugo
Vitor Hugo

Reputation: 1126

In Gorm Criteria: Filter collection inside domain by property

I grais 2.4.3 I have

class DomainFather {
   Set domainSon = []
}

And

class DomainSon {
   Date dataCreated
}

And I'm trying in a gorm criteria:

def c = DomainFather.createCriteria()
def data = c.list {
    createAlias("domainSon", "ds")
    projections {
       max("ds.dataCreated", "ds")
    }
}

Obviously does not work, but I have no idea how I'm supposed to do this. Any help is appreciate.

Upvotes: 0

Views: 310

Answers (1)

Emmanuel Rosa
Emmanuel Rosa

Reputation: 9895

The problem is you didn't set up an association between the domain classes. Try this:

class DomainFather {

    static hasMany = [sons: DomainSon]

}

Then you'll be able to use a query:

def c = DomainFather.createCriteria()
def data = c.list {
    projections {
       sons {
           max("dataCreated")
       }
    }
}

Upvotes: 2

Related Questions