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 8985101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:15:34+00:00 2026-06-15T21:15:34+00:00

I have 5 tables: User (Mark) Enterprise (Google) EnterpriseUser (Mark, Google) EnterpriseRight (LOGIN) EnterpriseUserRight

  • 0

I have 5 tables:

User (Mark)
Enterprise (Google)
EnterpriseUser (Mark,  Google)
EnterpriseRight (LOGIN)
EnterpriseUserRight (Mark-Google, LOGIN)

I would like to use GORM to query the database for all enterprises that Mark (Current User) has LOGIN rights to. I’d then like to be able to sort and paginate the results.

I previously did it by building a List, but I’d refer to return a ResultSet (which can still be sorted / paginated / queried)

My User.class (domain object) attempt (generating a List<Enterprise>)

public List<Enterprise>getEnterprises() {
    def list = new ArrayList<Enterprise>()
    for (EnterpriseUser eu: this.enterpriseUsers) {
        if (this.hasEnterpriseRights(eu.enterprise, [EnterpriseRight.LOGIN])) {
            list.add(eu.enterprise)
        }
    }
    return list
}

(but I can’t sort and paginate these results because they’re now a list. Would be nice if this query could return a resultset)

In English:

Find all Enterprise associated to this User where this user has the EnterpriseRight with the String name “LOGIN”. List in Alphabetical Order, Give me 10 results from Offset 10.

I’d post my code here, but I have no idea where to start.

Domain Objects Are:

class User {

    static hasMany = [userSystemRights: UserSystemRight, enterpriseUsers: EnterpriseUser]

    String email;   
    String passwordHash;
}    

class Enterprise {

    static hasMany = [enterpriseUsers: EnterpriseUser, measurements: Measurement]

    String name = ""
    String tradingName = ""
}

class EnterpriseUser {

    static belongsTo = [enterprise: Enterprise, user: User]
    static hasMany = [enterpriseUserRights: EnterpriseUserRight]

    Enterprise enterprise
    User user
    String interest
}

class EnterpriseUserRight {

    static belongsTo = [enterpriseUser: EnterpriseUser, enterpriseRight: EnterpriseRight]

    EnterpriseUser enterpriseUser
    EnterpriseRight enterpriseRight

}

class EnterpriseRight {

    public static final String LOGIN = "LOGIN"
    public static final String MANAGE_USERS = "MANAGE_USERS"
    public static final String MANAGE_SETTINGS = "MANAGE_SETTINGS"

    static hasMany = [enterpriseUserRights: EnterpriseUserRight]    

    String name
}
  • 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-06-15T21:15:35+00:00Added an answer on June 15, 2026 at 9:15 pm

    I don’t know if Grails also has a special DSL for queries, but in HQL, you would do:

    select distinct enterprise from EnterpriseUserRight enterpriseUserRight
    inner join enterpriseUserRight.enterpriseRight enterpriseRight
    inner join enterpriseUserRight.enterpriseUser enterpriseUser
    inner join enterpriseUser.enterprise enterprise
    where enterpriseRight.name = 'LOGIN'
    and enterpriseUser.user = :user
    order by enterprise.name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables user and log. I would like to join the user
i have three tables i would like to link in this one query. The
I have two sql tables for user login, store and retrieve data according to
I have five tables: User user_id | name -------------------- 0 | Mark 1 |
I have two tables user table user_id | name | 1 | peter |
I have two tables user and email. One user can have multiple emails so
i have four tables user-question contains two columns: questionID, userID, the questions that the
I have three tables: User: UserId (pk) FirstName Lastname Messages: MessageId (pk) Heading Body
I have 3 tables - user, service and ratings. The user's primary key is
Right now I have 3 tables: User, Roles, and User_Roles for the many-to-many association.

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.