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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:56:56+00:00 2026-06-04T16:56:56+00:00

I have a Statuses table which contains only an id and name field (Active,

  • 0

I have a Statuses table which contains only an id and name field (Active, Inactive, Pending, etc). I then have tables such as Users, Achievements, Badges for which each of these contain a status_id foreign key. Do the associations in my models look correct?

class Status < ActiveRecord::Base
  has_many :achievements
  has_many :badges
  has_many :users
end

class User < ActiveRecord::Base
  belongs_to :status
end

class Badge < ActiveRecord::Base
  belongs_to :status
end

class Achievement < ActiveRecord::Base
  belongs_to :status
end

I am struggling with how to properly read the difference between has_one and has_many in the case of a lookup table. I know that a user has one company and has one profile and a company has many users but this seems backwards to me.

  • 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-04T16:56:58+00:00Added an answer on June 4, 2026 at 4:56 pm

    The simplest association setup would be:

    class User < ActiveRecord::Base
      has_one :status
    end
    

    That exactly describes what you have posted. Your solution would work, but it is overkill for what you’ve described. All the association I posted above would do is add one method to the user model, i.e.

    @user = User.find(1)
    @user.status
    

    If on the other hand you wanted simple semantics for showing all the users with a particular status, THEN you’d add

    class Status < ActiveRecord::Base
      has_many :users
    end
    

    so now you could do:

    @status = Status.find_by_description('Active').first()
    
    @status.users
    

    Note that in BOTH cases, all that is needed is for the users model to have an attribute ‘status_id’

    Belongs_to is better suited when there is an implicit hierarchy , i,e,

    class Child << ActiveRecord::Base
       belongs_to :parent
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using MS SQL 2008 and I have a table of statuses (id, name)
I have a child table that contains the history of statuses for the particular
I have table SR with some records with statuses (more then 5 records this
I have Customers table: Customer(id, name status_id). I have Statuses table: Status(id, name, code).
When I have only two statuses for an object, like 'active' and 'retired' for
I have several models that belong_to :status . Statuses are: Active Hidden Banned I
My current situation is I have a custom workflow which include many statuses. For
This one really has me stumped. I have a documents table which hold info
I have a table which has columns of data that contain status. Two example
Here is my situation, I have a table called Statuses ( statusID, statusName )

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.