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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:27:56+00:00 2026-05-31T13:27:56+00:00

My question is based on the following (simplified) Grails domain class class Dimension {

  • 0

My question is based on the following (simplified) Grails domain class

class Dimension {

    String name

    static hasMany = [
        children: Dimension,
        parents: Dimension
    ]
}

Is there a way to map the many-to-many parents/children relationship to a single join table?

  • 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-31T13:27:57+00:00Added an answer on May 31, 2026 at 1:27 pm

    As far as I know, the only way to do that is to create another domain class that represents a parent-child relationship.

    class DimensionDependency {
      Dimension parent
      Dimension child
    
      static belongsTo = Dimension
    }
    
    class Dimension {
      static hasMany = [parentDependencies: DimensionDependency]
      static mappedBy = [parentDependencies: 'child']
      static mapping = { parentDependencies cascade: 'all-delete-orphan' }
    }
    

    The mappedBy keywords specifies that the object refering to a DimensionDependency is always the child. By specifying all-delete-orphan in the mapping, we make sure that when removing a parentDependency from a child, the associated DimensionDependency is deleted from the database.

    You may also add convenience methods to your Dimension class to encapsulate operations on DimensionDependencies, to make the interface more GORM-like.

      static transients = ['children', 'parents']
    
      Set<Dimension> getChildren()
      {
        AssignmentDependency.findAllByParent(this).child
      }
    
      Set<Dimension> getParents()
      { 
        parentDependencies?.parent ?: []
      }
    
      Dimension addToParents(Dimension parent)
      {
        if (!parentDependencies.find { it.parent == parent && it.child == this })
        {
          addToParentDependencies(new DimensionDependency(parent: parent, child: this))
        }
        return this
      }
    
      Dimension removeFromParents(Dimension parent)
      {
        def dep = parentDependencies.find { it.parent == parent }
        removeFromParentDependencies(dep)
        dep.delete(flush: true)
        return this
      }
    

    I’ve been using this approach for some time and have had no trouble so far.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Based on the following question: Check if one string is a rotation of other
My question is concerning SQL connection status, load, etc. based on the following code:
Now following my series of python newbie questions and based on another question .
I have the following tables defined declaratively (very simplified version): class Profile(Base): __tablename__ =
This question is based on the thread . I have the following Git-prompt at
I have the following worksheet #1 (simplified for the question) of person and age:
I have a ModelForm field that is based on the following Model: class Phrase(models.Model):
I have a question based on this question In the section http://www.parashift.com/c%2B%2B-faq-lite/private-inheritance.html#faq-24.3 the following
Looking at the following (simplified) hierarchy of classes: > Email (base class) > SimpleEmail
This is a further question based on this answer: How can I implement a

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.