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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:41:49+00:00 2026-05-20T13:41:49+00:00

I have a User domain class, and a List one. Each list must have

  • 0

I have a User domain class, and a List one.

Each list must have an author (a user) and each user must have a “primary list”. Only some of the lists will have the “primaryList” statute.

So.. somthing like

 User:
    List primaryList

 List:
    User author

    static belongsTo = User

Of course this does not work as intended because the two relations are mistakenly taken as only one. I should also add a hasMany on the User and other belongsTo to the List…, but I don’t want to complicate the example because I want to get the right answer from you.

  • 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-20T13:41:50+00:00Added an answer on May 20, 2026 at 1:41 pm

    You may need to use mappedBy to explain how the fields in User and List line up. Here are a couple domains that I wrote that allow a User to author many Lists but only set one to be “primary”. There are a couple extra nullable constraints so you can use the scaffolded UI without getting into a chicken-and-egg scenario.

    class User {
        String name
        FooList primaryList
    
        static hasMany = [authoredLists: FooList]
    
        static mappedBy = [primaryList: 'primaryOwner', authoredLists: 'author']
    
        static constraints = {
            primaryList nullable: true, unique: true
            authoredLists nullable: true
        }
    
        String toString() { name }
    }
    

    I named this class “FooList” just to avoid confusion with the standard List class:

    class FooList {
        static belongsTo = [author: User, primaryOwner: User]
    
        static constraints = {
            primaryOwner nullable: true, display: false
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So in my domain I have 3 objects. User, Item and Tag. Each user
Let's say you have a domain entity User and you want to support the
I have a database with user 'dbo' that has a login name domain\xzy. How
I have created an app to standardize user creation for our AD domain. Now
I have user generated podcasts, each with their own RSS feed. Is there a
Domain outlay: class User { String username static hasMany = [userRoles: UserRole] } class
Right now, I have a domain entity named StyleBundle. This StyleBundle takes a list
I have three classes (domain, role and user). Domain and role are properties of
I have the next two domain classes in a grails application: class Room {
I have the following domain object: public class DomainObject<T,TRepo> where T : DomainObject<T> where

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.