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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:27:18+00:00 2026-06-14T16:27:18+00:00

Given two models: class User < ActiveRecord::Base attr_accessible :name, :user_status end class UserStatus <

  • 0

Given two models:

class User < ActiveRecord::Base
  attr_accessible :name, :user_status

end

class UserStatus < ActiveRecord::Base
  attr_accessible :descr
end

The user.user_status column is intended to be a single ID which can be used to join against UserStatus for additional information, such as status icon and description.

UserStatus is a read-only reference table which will have very few rows, all unique. Let’s say it has only four rows:

{ :id => 0, :descr => 'New' },
{ :id => 1, :descr => 'Banned' },
{ :id => 2, :descr => 'Active' },
{ :id => 3, :descr => 'Unverified' }

Should I bother with ActiveRecord associations for reference tables? If so, what is the proper ActiveRecord association if I want to (or must) store the associated UserStatus ID in the user table? From what I can tell, based on the documentation, ‘User belongs_to :user_status’ is my best bet, but linguistically this is failure; because a User does not “belong to” a status, a user is in a state or has a status. Or is this just too hair-splitting of 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-14T16:27:19+00:00Added an answer on June 14, 2026 at 4:27 pm

    belongs_to doesn’t always make linguistic sense, but in this case it’s just what you want.

    UserStatus has_many :users
    User belongs_to :user_status
    

    Which also allows the status to find all users in that state, which can be useful.

    naughtyPeople = UserStatus.where(descr: 'Banned').users
    

    What’s more important, linguistically, is the API you settle on to get this data.

    User.find(123).user_status.descr
    

    That kind of sucks. It has the relations you want, but the API is pretty verbose.

    class User
      def status
        user_status.descr
      end
    end
    
    User.find(123).status
    

    Much better.

    Or even possibly this!

    class User
      def status
        user_status.descr
      end
    
      def status=(status_string)
        self.user_status = UserStatus.where(descr: status_string).first
      end
    end
    
    user = User.find(123)
    user.status = 'Banned'
    user.user_status #=> { id: 3, descr: "Banned" }
    

    How far you want to massage it is up to you.

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

Sidebar

Related Questions

I have two models class User < ActiveRecord::Base has_one :work end class Work <
I have two model as follows class User < ActiveRecord::Base validates_associated :account end class
Given the following two models: class Card(models.Model): disabled = models.BooleanField(default=False) class User(models.Model): owned_cards =
Given these two models: class Profile(models.Model): user = models.ForeignKey(User, unique=True, verbose_name=_('user')) about = models.TextField(_('about'),
I have model User class User < ActiveRecord::Base has_and_belongs_to_many :roles attr_accessible :login, :email, :password,
I have two models class Status(models.Model) name = models.CharField(max_length=25) rank = models.PositiveSmallIntegerField() class MyModel(models.Model)
I'm using Django and have two classes: class PR(models.Model): Jq = models.ForeignKey(JQ) user =
models: #StatusMessage model class StatusMessage < ActiveRecord::Base belongs_to :users default_scope :order => created_at DESC
Given the following two models: User (id) FbFriendCache(user_id,fb_user_id) I would like to be able
Given two methods on the same class in Java : public void doSomething( Person

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.