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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:24:15+00:00 2026-05-24T16:24:15+00:00

I have a rails 3.1 project using devise for authentication. I have several user

  • 0

I have a rails 3.1 project using devise for authentication.

I have several user types, each taking really remarkably different fields in the database. I had different models for each, but there was enough overlapping functionality between models such as messaging that it makes sense to have a single model. This was particularly an issue when dealing with messaging between users of different types.

Should I leave them all as individual table or move them into a single table? Multiple Table Inheritance really doesn’t make a lot of sense given the fact that we’ll be looking up users all the time. It would simply be too expensive join wise.

It just feels really dirty to have all the unused columns for each user type in the table.

Thought?

  • 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-24T16:24:15+00:00Added an answer on May 24, 2026 at 4:24 pm

    Personally I don’t think that unused columns are that much of a big deal, however if it really bothers you, you might want to try an unorthodox solution. Have you considered ‘bucketing’ all the attributes which aren’t common to your different types of users? I am talking about using a plugin such as attr_bucket.

    Essentially you would add am extra column to you db table:

    t.text :non_common_attributes
    

    Then in each of your different user models (that inherit from a common class) you would have something like:

    class UserType1 < User
      attr_bucket :non_common_attributes => [:first, :second, :third]
    end
    
    class UserType2 < User
      attr_bucket :non_common_attributes => [:fourth, :fifth]
    end
    

    You would use the attributes just like they were defined in the normal way, but when you save the model into the database, all those attributes would be serialized via YAML and stored in the :non_common_attributes column. When you load the model again, they will be transparently deserialized.

    There are some caveats, such as the fact that you don’t want to search for users via any of the bucketed attributes (since you can’t index on those attributes) etc. But in your case it may just be what you’re after. I wouldn’t worry too much about the cost of serializing and deserializing, it probably won’t be an issue since you’re unlikely to be saving/loading thousands of users at the same time.

    Infact, I have used a similar solution (but hand rolled rather than using a gem), with a model where most attributes need to be encrypted. I just bucket all the attributes together and encrypt the bucket – works a treat.

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

Sidebar

Related Questions

I'm using the devise authentication plugin under rails 3. At the moment, I have
I'm using the devise authentication plugin under rails 3. At the moment, I have
I have started a project using Rails 3.0. I am using devise for the
I just started using CakePHP for a small project. I have rails experience, and
If I am using spork in my rails project and have a spec_helper.rb file
I'm using devise & devise_invitable in a rails 3 project, and I'm trying to
I'm starting a project using Rails and have bought a domain with Dreamhost. I've
This is a Rails 3 project using jQuery 1.4.4. I have an index action
I have a normal Rails project (without Active Record) using CouchDB (couchrest_model) as a
I am using Devise. I need to push the same rails project to two

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.