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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:31:08+00:00 2026-05-25T09:31:08+00:00

This is my Feedback model: class Feedback < ActiveRecord::Base belongs_to :user end # ==

  • 0

This is my Feedback model:

class Feedback < ActiveRecord::Base
    belongs_to  :user
end
# == Schema Information
#
# Table name: feedbacks
#
#  id          :integer         not null, primary key
#  poster_id   :integer
#  receiver_id :integer
#  content     :string(255)
#  created_at  :datetime
#  updated_at  :datetime

This is my User model:

class User < ActiveRecord::Base
    has_many    :feedback
end
# == Schema Information
#
# Table name: users
#
#  id         :integer         not null, primary key
#  email      :string(255)
#  f_name     :string(255)
#  l_name     :string(255)
#  username   :string(255)
#  role_id    :integer
#  picture    :string(255)
#  about_me   :string(255)
#  website    :string(255)
#  created_at :datetime
#  updated_at :datetime

What I would like to do is retrieve all the feedback for a particular user. But, at my console, when I do t = User.first and then t.feedback, I get the following error:

 Feedback Load (0.2ms)  SELECT "feedbacks".* FROM "feedbacks" WHERE "feedbacks"."user_id" = 1
SQLite3::SQLException: no such column: feedbacks.user_id: SELECT "feedbacks".* FROM "feedbacks"  WHERE "feedbacks"."user_id" = 1
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: feedbacks.user_id: SELECT "feedbacks".* FROM "feedbacks"  WHERE "feedbacks"."user_id" = 1

Now that is saying that I have no column user_id in my Feedbacks table, which makes sense – because I don’t.

What I really want to happen is, I want to store the user_id of a user that posts feedback as the poster_id, and when someone receives feedback I want the user_id to be stored in the feedback object as receiver_id.

How do I do that?

Thanks.

P.S. Using Rails 3.1…if that has any bearing.

P.P.S. In my User model the has_many :feedback line looks weird, because I know it should be plural. But has_many :feedbacks looks even worse 😐 What should I do for that too?

P.P.P.S. I looked at the foreign_key attribute of associations, but wasn’t sure how to get it to work in this situation – would the association be belongs_to :poster_id, :foreign_key => user_id? That looks weird and doesn’t seem to fit the description in the api documentation of the foreign_key attribute.

  • 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-25T09:31:09+00:00Added an answer on May 25, 2026 at 9:31 am

    Your associations should be defined like this:

    class Feedback < ActiveRecord::Base
        belongs_to :poster, :class_name => 'User'
        belongs_to :receiver, :class_name => 'User'
    end
    
    class User < ActiveRecord::Base
        has_many :feedbacks_as_poster, :foreign_key => :poster_id, :class_name => 'Feedback'
        has_many :feedbacks_as_receiver, :foreign_key => :receiver_id, :class_name => 'Feedback'
    end
    

    If you are not sure about what the association name means or you don’t like the name, you should possibly think about a little bit more about your model, maybe the naming doesn’t reflect what you’re trying to model with your objects.

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

Sidebar

Related Questions

I have an object model like this: public class Quantity { public decimal Weight
any help with this would be great. I have a model public class Master
I'm kind of interested in getting some feedback about this technique I picked up
Based on feedback I got from this question , I'm interested in using Lazy
I've seen a feedback tab on this page and many others (e.g. UserVoice). I
I want to create a tab/widget/thingymajiggy like the feedback-thing in this picture: That behaves
I was hoping I could get feedback on major changes to how a model
(Django 1.x, Python 2.6.x) I have models to the tune of: class Animal(models.Model): pass
I have two models. class User has_one :spec, :dependent => :destroy # returns true
Given the Django models: class ContainerOwner(models.Model): id = models.IntegerField() class Container(models.Model): owner = models.ForeignKey(ContainerOwner)

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.