grails - How to fix the totalCount of the list returned by the list method of the GORM query for a specified Criteria? -
i getting wrong result totalcount
property of list returned list function of gorm query.
i think due issue includes duplicate results. results returned in list correct count seems wrong.
how can fix it?
i tried following not work:
trace.setresulttransformer(criteriaspecification.projection)
following gorm query:
def trace = trace.createcriteria() def results = trace.list(max:max, offset:offset) { createalias('module','mod', criteriaspecification.left_join) createalias('symbol','sym', criteriaspecification.left_join) createalias('fault', 'fault',criteriaspecification.left_join) createalias('fault.report', 'report', criteriaspecification.left_join) createalias('fault.tgmap', 'tg', criteriaspecification.left_join) createalias('tg.tracegroup16','tr', criteriaspecification.left_join) projections { property('fault.id') property('tr.geckid') property('report.email') property('fault.ver') property('fault.shortos') property('fault.faultdate') property('framenumber') property('mod.module') property('sym.symbol') groupproperty 'fault.pid' groupproperty 'report.file' } // handle unknown module case if (module.length() > 0 && symbol.length() > 0 && module != symbol) { , { like('mod.module', '%' + module + '%') like('sym.symbol', '%' + symbol + '%') } } else if (module.length() > 0 && symbol.length() > 0 && module == symbol) { or { like('mod.module', '%' + module + '%') like('sym.symbol', '%' + symbol + '%') } } else if (module.length() > 0) { like('mod.module', '%' + module + '%') } else if (symbol.length() > 0) { like('sym.symbol', '%' + symbol + '%') } order("fault.faultdate", "desc") }
this pretty annoying problem - can filter out duplicates using distinct
projection, you'll find pagination messed up. end approach this:
- query totalcount using
countdistinct
- query again distinct ids range of rows (e.g. rows 1 - 10) using
distinct('id')
projection - create
pagedresultlist
instance, , query again usingdomainclass.getall(ids)
- set
totalcount
, list returneddomainclass.getall(ids)
manually onpagedresultlist
you can see examples using approach in excellent filter pane , quick search plugins.
not ideal, work , use cases performance impact of doing 4 queries (instead of 2) isn't bad.
Comments
Post a Comment