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

  • Home
  • SEARCH
  • 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 9002919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:38:17+00:00 2026-06-16T00:38:17+00:00

Here is the situation: a user table contains data that overlap with other users’

  • 0

Here is the situation: a user table contains data that overlap with other users’ data such as country, age group, gender, etc.

In MySQL, I would use three tables or two. In the case storing country, I would use three tables: one would the be user table, the other country table, and the last one that joins the two. (Of course I could use two tables if one user has one country.)

ex) user(id, otherUserInfo),
userCountry(id_user, id_country),
country(id, countryName)

Being new to Grails, I was wondering what’s the best way to represent this schema. Is it necessary to create 2-3 domain classes? Or is there some magical feature (like so many other Grails features (: ) to do this in a single domain class.

  • 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-16T00:38:18+00:00Added an answer on June 16, 2026 at 12:38 am

    More than likely you could do it with two.

    class User {
        //other user info
    
        //if user only has one country
        Country country
    
        //if user has many countries
        static hasMany = [countries: Country]
    }
    
    class Country {
        //country info
    }
    

    Since you probably don’t want a Country to belong to the User, you don’t need anything in the Country class to indicate ties back to the User. Grails/Gorm will handle creating the linking entities in either of these cases.

    If the user has many countries and you needed to store other information regarding the relationship you would need to create your own join table. For example if you needed to keep the number of visits the user has made to the country:

    class User {
         //other user info
    
        static hasMany = [userCountries: UserCountry]
    }
    
    class UserCountry {
        static belongsTo = [user: User]
        Country country
        int numberOfVisits
    }
    
    class Country {
        //country info
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my situation. I have a user table and a password_reset table which references
Here is my situation. I am building an application that contains some heavy mathematical
The Situation I have a table in a DB that contains job types, basically
I'm creating (really, re-creating) an app that has existing user and other data in
Here the Situation . I am having 2 million records in table . Just
I have an situation here that looks very like a SELECT N+1 from the
Here is my situation. I need to create a report that shows each open
Here's the situation: I would like to iterate through a table with input controls,
I have a jsfiddle here: http://jsfiddle.net/ybZvv/22/ The situation I have is that if you
Here's the situation. Multi-million user website. Each user's page has a message section. Anyone

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.