hibernate - How do you make a distinct query on GORM subdocument fields? -


given grails 2.3.8 , mongo 2.6.0, , (simplified) domain class:

db.account.findone() {     "name":"test account",     "customer": {         "state": "ca"     } } 

where every account has customer subdocument "state" string. list of states across customers, think this:

def states = account.createcriteria().list {     projections{         distinct("customer.state")     } } 

but doesn't work because of existing bug - https://jira.grails.org/browse/gpmongodb-397

is there workaround?

i can this: account.collection.distinct("customer.state") there more grails-ish way it?

you can use "criteria.distinct_root_entity" distinct record.

def users = account..withcriteria {         resulttransformer criteria.distinct_root_entity } 

Comments