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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:30:16+00:00 2026-06-03T09:30:16+00:00

I have a standard devise user model with the usual fields. This is for

  • 0

I have a standard devise user model with the usual fields.

This is for a situation where people are either looking for a place to stay, or they have a place to stay. So I have two categories of user that a person can be. These two categories are very distinct (i.e. a person looking for a place to stay will have very different fields to a person who has a place to stay).

So a User has:

User: name, email, password, profile_id

A User can also have a Profile (i.e. they are looking for a house).

Profile: age, sexuality, religion, occupation

That’s what I have at the moment. Now I need to change that slightly, so a User can have a profile OR… they can have a House (i.e. they have a house and are looking for more people):

House: price_per_week, address, etc

How best to model this in ActiveRecord? Polymorphic association of some kind?

  • 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-03T09:30:18+00:00Added an answer on June 3, 2026 at 9:30 am

    I’ve found in general that polymorphic relationships don’t work well over time if the objects they are modeling are even mildly different. For your case I’d recommend keeping the two objects separate.

    In general, the best way is to consider the way you want to retrieve the data. For example, I’d imagine you want to access both:

    @user.house
    

    or

    @user.profile
    

    So I’d recommend beginning by setting up relationships (that can be optional) between the users table and both the profiles and houses table. I’d also add a type field that can be used to determine which of the two types the users are.

    This allows users to be of either type and allows them to have both a profile and a house.

    So both houses and profiles belong_to users, and users have_many (or have_one) houses and profiles

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

Sidebar

Related Questions

I've heard they have standard GUI guideline, but I can't seem to find a
I have a standard active record model with an attributes that is required: class
I'm using Rails 3 with Devise for user auth. Let's say I have a
Ok, So I have standard sencha-touch panel, and because this application needs to be
I'd like to have additional attributes for my User model and don't want to
On core website I use standard Devise configuration for user authentication. In routes.rb: devise_for
I have users class User < ActiveRecord::Base devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable attr_accessible
It seems when a user logs out via standard Devise controllers, Devise destroys the
I have standard source code package under Linux which requires to run ./configure make
I have a mobile site running with jQuery Mobile. I want to have standard

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.