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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:48:17+00:00 2026-05-22T01:48:17+00:00

I am setting up private messaging in my application and was wondering what the

  • 0

I am setting up private messaging in my application and was wondering what the best way to do this would be, I have a message model that has 2 columns, a to_id and from_id

I have the association set in the message model like so:

class Message < ActiveRecord::Base
  belongs_to :recipient, :class_name => 'User', :foreign_key => "to_id"
  belongs_to :sender, :class_name => 'User', :foreign_key => "from_id"

end

How would i set up the relationship in the user model? i want to have a :received messages association and a :sent_messages Association.

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-22T01:48:18+00:00Added an answer on May 22, 2026 at 1:48 am

    You can specify the :foreign_key on both sides, like this:

    class User < ActiveRecord::Base
      has_many :sent_messages, :class_name => 'Message', :foreign_key => 'from_id'
      has_many :received_messages, :class_name => 'Message', :foreign_key => 'to_id'
    end
    

    I know Rails 3 has an :inverse_of option you can pass as well, but I don’t have any experience with that.

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

Sidebar

Related Questions

This is a segment of code I have for setting the masterpassword: private void
I have the following mongodb model: class Setting_Model private() extends MongoRecord[Setting_Model] with ObjectIdPk[Setting_Model] {
I have a problem while setting a private attribute on a PHP class, my
I have a web application in Drupal 6 that shows video content to users.
When setting up a project in Jenkins that's hosted on bitbucket what would I
We have REST API that we want only our domain has access to and
I wonder whether I can setting up a private maven repository based on my
Setting up a project structure; I am thinking is it better to have somewhat
Setting the scene: My asp.net web application carries a version number which is incremented
I'm trying to create a boost::function that allows setting of a member variable of

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.