I'm using Grails and I'm trying to figure out how to get all the distinct values of a domain class' property. In other words I'm looking for all the distinct values for a column. However, I'm not sure how to translate this into a GORM statement, preferable a criteria statement.
I'm open to either something that gives me a list of domain classes (with each having a distinct value for the property in question) and I collect all the properties values. Or something that gives me the distinct property values directly.
I think all you need to accomplish this is to use projections
and distinct
. According to the documentation this will provide you with a list of distinct values of a property from your domain class.
def results = MyDomain.withCriteria {
projections {
distinct("theDistinctProperty")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With