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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:38:04+00:00 2026-06-12T17:38:04+00:00

I have multiple belongs_to relationships to the same model. Modeling messages between two users

  • 0

I have multiple belongs_to relationships to the same model. Modeling messages between two users as follows (in the Message model):

  belongs_to :to, :class_name => 'User', :foreign_key => 'to_id'
  belongs_to :from, :class_name => 'User', :foreign_key => 'from_id'

  attr_accessible :to, :from # ...

The corresponding has_many calls are in the User model. Everything works in the spec and the console as I need it to, with the exception of the following deprecation warning (for both from_id and to_id):

DEPRECATION WARNING: You're trying to create an attribute `from_id'. Writing arbitrary attributes on a model is deprecated. Please just use `attr_writer` 

The relevant spec follows:

  it "can associate users" do
    User.delete(:all)
    ufrom = FactoryGirl.create(:DrKevorkian)
    ufrom.save!
    uto = FactoryGirl.create(:JohnSmith)
    uto.save!

    m = Message.new
    m.from = ufrom   # <-- Warning here
    m.to = uto       # <-- Warning here
    m.save

    m.from.id.should == ufrom.id
    m.to.id.should == uto.id

  end

It seems to me the warning is happening as a result of the belongs_to association — is there a cleaner/better way to do this?

Thanks very much.

  • 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-06-12T17:38:06+00:00Added an answer on June 12, 2026 at 5:38 pm

    My experience is that you get this warning if you forgot to run rake db:migrate and rake db:test:prepare after changing your schema.

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

Sidebar

Related Questions

I've built a simple Friend model, which allows Users to have multiple friends. Here's
Problem definition. I have multiple clients with multiple users. Each client needs to be
I'm using Grails, and I have a domain model with multiple hasMany attributes to
I have two tables, products and category. A product can be in multiple categories.
I'm working on a Rails app where Users can have multiple roles, e.g. Manager,
I have a table joining two models in a has many through relationship. Users
I have a fundamental design question in modelling the relationships between the entities for
I have a User and Account model. The relationship is User belongs to Account,
I have multiple ajax requests with javascript code as response, and I need to
I have multiple projects which are to be hosted together in a Tomcat container,

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.