0

In my app I use createCriteria for getting a list according some criteria. roleMapping contains user.

I use the following code:

def getTeamOfCompany(def company,def offset=0){
        def c = roleMapping.createCriteria()
        def result = c.list{
            eq('company',company)
            eq('isCurrentCompany',true)
            firstResult offset
            maxResults 10
            distinct('user')
            user{
                order "lastname", "asc"
            }
        }
    return result
}

I use the distinct in order to not get the same user twice, but it didn't work.

If I put projections on the distinct I'll get a list of users instead roleMapping

defectus
  • 1,947
  • 2
  • 16
  • 21
Sarit Sara
  • 101
  • 2
  • 13
  • 1
    Can you try `result.unique{ it.user }` on previous code which was giving you roleMapping collection. Projections actually select columns for you – Anant Kolvankar Jun 03 '15 at 14:24
  • what do you exactly want? do you want one role per one user? why? – dsharew Jun 03 '15 at 14:48
  • result.unique{ it.user } is a neat trick to solve the problem, but breaks the proper pagination behavior of the criteria query. – Schmick Jan 25 '19 at 21:22

0 Answers0