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

  • Home
  • SEARCH
  • 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 7083855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:13:47+00:00 2026-05-28T07:13:47+00:00

User has_many :codes has_many :redemptions Code belongs_to :user has_many :redemptions Redemptions has_one :code belongs_to

  • 0

User
has_many :codes
has_many :redemptions

Code
belongs_to :user
has_many :redemptions

Redemptions
has_one :code
belongs_to :user

Redemptions Model:

  class Redemption < ActiveRecord::Base
  has_one :code
  belongs_to :user

  validates :code_id, :presence => true
  validates :user_id, :presence => true

  after_create :increment_points
  def increment_points
    self.code.user.increment!(:points)
  end 

end

When I create a new redemption it returns the following error:

PGError: ERROR:  column codes.redemption_id does not exist
LINE 1: SELECT  "codes".* FROM "codes"  WHERE "codes"."redemption_id...
                                              ^
: SELECT  "codes".* FROM "codes"  WHERE "codes"."redemption_id" = 17 LIMIT 1

Is something wrong with my associations? I have mapped it out and believed I could back track up the association redemption -> Code -> User

The one caveat to this issue is that a redemptions user is not the user that I am trying to increment points on. The code was created by a user and that is the user I am trying to update…

thoughts?

  • 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-28T07:13:48+00:00Added an answer on May 28, 2026 at 7:13 am

    has_many/one and belongs_to needs to go together. when you declare Redemption has_one :code, Rails expects you put a redemption_id on codes table and have the corresponding belongs_to declared on Code.

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

Sidebar

Related Questions

i have following code: class Item < ActiveRecord::Base belongs_to :user has_many :transactions #scope :active,
I have a Post model: class Post < ActiveRecord::Base belongs_to :user has_many :taggings, :dependent
I have 2 models: Video: class Video < ActiveRecord::Base belongs_to :user has_many :thumbnails attr_accessor
models/user.rb class User < ActiveRecord::Base has_many :clubs, :dependent => :destroy has_many :announcements, :dependent =>
I have three models: class User < ActiveRecord::Base has_many :projects, :through => :permissions class
I have a Tag model: class Tag < ActiveRecord::Base has_many :taggings, :dependent => :destroy
I have 3 models: User has_many :questions has_many :corrections end Question has_one :correction belongs_to
I have a User and Group model. User has_many Groups and Group belongs_to User
I have the following models class Project < ActiveRecord::Base has_many :project_members has_many :members, :through
I have a model Whitelabel and a User has_many :whitelables I have a custom

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.