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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:28:40+00:00 2026-05-18T04:28:40+00:00

All My problem is I’m creating a 1-to-many relationship in GORM and expect 2

  • 0

All

My problem is I’m creating a 1-to-many relationship in GORM and expect 2 database tables to be created as backing objects. 3 are created which makes SQL queries overly complex.

I’ve created a close variant on the 1-to-many in the GORM documentation:

class Status {

   List errorMessage

   static hasMany = [errorMessage:ErrorMessage]
}

and the error message class:

class ErrorMessage {

   String message

   static belongsTo = Status
}

I expected this to create two database tables:


CREATE TABLE status {
   ID NUMBER(19,0),
   VERSION NUMBER(19,0),
   //other fields
}

CREATE TABLE error_message {
   ID NUMBER(19,0),
   VERSION NUMBER(19,0),
   STATUS_ID NUMBER(19,0),
   MESSAGE VARCHAR(255)
   //other fields
}

but actually it wants a third table,



CREATE TABLE status_text {
    status_text_id NUMBER(19,0),
    text_idx NUMBER(19,0), 
    text_id NUMBER(19,0)
}

Adding Status to the ErrorMessage (a hack as I don’t want ErrorMessage to have a reference to Status) class removes the third table but keeps the second foreign key resulting in the Text child object having two foreign key fields.

What I want is simple – just a set of objects attached to the parent will be deleted when it is – any thoughts what I’m doing wrong?

Thanks

  • 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-18T04:28:41+00:00Added an answer on May 18, 2026 at 4:28 am

    I don’t think you can satisfy both requirements, i.e. that you have cascading deletes and no join table. You need the belongsTo to get cascading deletes and that makes the relationship bidirectional. To remove the join table, name the belongsTo with the Map syntax:

    class ErrorMessage {
       String message
       static belongsTo = [status: Status]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem Hello all! I have this code which takes my jpg image loops through
I have a problem all the applications im creating are getting installed in phones
I've been searching for an answer to this problem all day long. I'm creating
Hello all my problem is : We have to create a system in which
I have the following validation code, which properly highlights all problem areas in my
So I'm been pounding on this problem all day. I've got a LinqDataSource that
Good day everyone. I have been having the same problem all day at work
This is a common problem for all developers, I am looking for the best
I have a (big) problem that all of you that work with Webforms might
I had no problem at all running the following code on a local server,

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.