Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6387883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:12:32+00:00 2026-05-25T03:12:32+00:00

I have the following method in a service, please note the .user on the

  • 0

I have the following method in a service, please note the .user on the def usersByRole line:

def getUsersByRole(String desiredRole1, String desiredRole2, String desiredRole3) {
    Role role1 = Role.findByAuthority(desiredRole1)
    Role role2 = Role.findByAuthority(desiredRole2)
    Role role3 = Role.findByAuthority(desiredRole3)
    def usersByRole = UserRole.findAllByRoleInList([role1, role2, role3]).user
    return usersByRole
}  

It works good, but when a user has multiple roles (i.e. ROLE_ADMIN, and ROLE_OWNER) then that user exists twice in the collection if both of the previously mentioned roles are given as parameters. Is there any clean way I can make the collection contain only unique results?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:12:32+00:00Added an answer on May 25, 2026 at 3:12 am

    A similar question as yours can be found here: GORM createCriteria and list do not return the same results : what can I do?

    Method 1

    If you want to return unique list of users directly from DB query then you can use listDistinct on User (supposing that user has a roles OneToMany association with UserRoles)

    User.createCriteria().listDistinct {
        roles {
           in 'role', [role1, role2, role3]
        }
    }
    

    Method 2

    You can also try to query UserRole directly and group by User using the groupProperty (see http://www.grails.org/doc/latest/ref/Domain%20Classes/createCriteria.html)

    Method 3

    Remove duplicated users from the returned list:

    UserRole.findAllByRoleInList([role1, role2, role3])*.user.unique()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have the following method: def call_http_service(url, url_params) begin conn = create_connection(url) resp =
I have the following method: public string Phase(string phase) { return Phase 1; }
I am using java with spring3 i have following controller's service method @Override public
I have following method which I am using to load ActiveX control dynamically, Dim
I have the following method, which takes in the name of a file as
I have the following method that returns void and I need to use it
I have the following method where I want to test the event.status property only
I have the following method in my UIButton class: - (id)initWithCoder:(NSCoder *)aDecoder{ self =
I have the following method which is called when the value Edit Class... is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.