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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:10:02+00:00 2026-05-27T15:10:02+00:00

Here I am facing an unusual issue. Everything should work in my understanding (as

  • 0

Here I am facing an unusual issue. Everything should work in my understanding (as a grails beginner), but not working 🙁

I have a domain class User. User can have many friends and many friendRequests. There is a function in domain class to send friend request to other user. here is the code from User Domain –

static hasMany = [friends: User, friendRequests: FriendRequest]
static mappedBy = [friendRequests:'receiver']

def sendFriendRequest(User toUser) {

    if(!isFriend(toUser)) {
        FriendRequest requestToSend = new FriendRequest(status:'pending', sender: this) 
        toUser.addToFriendRequests(requestToSend)
        return true
    }
    return false
}

And the FriendRequest class is –

class FriendRequest {

    String status
    User sender

    static constraints = {
    status(inList:["accepted", "pending", "rejected"])
    }

    static belongsTo = [receiver:User]
}

Now, The problem is, I am expecting the current User object, from which I am running the function will be set as sender of friendRequest. But strangely the toUser, which I m passing as param is being set as sender!

Can anyone please explain what I am missing?

  • 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-27T15:10:03+00:00Added an answer on May 27, 2026 at 3:10 pm

    The addToFriendRequests method is overriding sender. It thinks that FriendRequest.sender is the inverse of User.friendRequests

    Your FriendRequest class will need two references to User: one for the sender, and one for the receiver. You’ll also need to tell gorm which one maps back to the friendRequests relationship. You can do this with a mapping in your User class:

    static mappedBy = [friendRequests:'receiver']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the issue I am having: I have a large query that needs
I'm here facing a problem with a Java web project. The project I'm working
ghost noscript tag more info here I am facing exactly this issue, how shall
I am facing a strange problem here. I have two projects, each of them
The problem I’m facing here is that the current regex I created does not
here is briefly the problem I'm facing: I have built a custom Content Query
here's another strange behaviour I'm currently facing. I have an application deployed on a
I facing a weird problem here. I already have a simple try-out for jquery
Here is the scenario I am facing. I have installed Windows 7 Professional on
Here I am facing one more challenging issue and as usual turning on this

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.