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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:10:14+00:00 2026-06-08T21:10:14+00:00

Ok, so I have three different objects: a person, place, and equipment. Each can

  • 0

Ok, so I have three different objects: a person, place, and equipment. Each can have an address, in most cases multiple address and multiple phone numbers. So my thought is create the specific object tables, the have an address and a phone table. Here my question:

So typically, in my SQL world, I would just have an object_id column in the address and phone table and put a id of the object in the object id column, and then select all the address or phone records that match.

I could do this, do find_by_sql and get the records but I’d rather stay within the ActiveRecord paradigm. So does that mean I should have an id column in the table for each object, so a person_id, place_id, etc.

What’s the “right” way to model this?

  • 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-08T21:10:15+00:00Added an answer on June 8, 2026 at 9:10 pm

    You can create polymorphic associations with activerecord, so you can add object_id and object_type to the addresses and phone_numbers tables, and specifying the associations like this:

    class Address
      belongs_to :object, :polymorphic => true
    end
    
    class PhoneNumber
      belongs_to :object, :polymorphic => true
    end
    
    class Person
      has_many :addresses, :as => :object
      has_many :phone_numbers, :as => :object
    end
    
    class Place
      has_many :addresses, :as => :object
      has_many :phone_numbers, :as => :object
    end
    
    class Equipment
      has_many :addresses, :as => :object
      has_many :phone_numbers, :as => :object
    end
    

    This way, Person.first.addresses should run a query like Addresses.where(:object_type => "Person", :object_id => Person.first.id), and vice versa for the rest of the models and associations.

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

Sidebar

Related Questions

I have three different List collections. How can I show them in one ListBox
My problem is that I have three different stock sizes for each product that
I have developed three different versions(as different projects) of an app(large,normal,small). How can I
If I have three entities, Project, ProjectRole and Person, where a Person can be
I have a multiple classes each with different member variables that are initialized trivially
I have a collection of MDI forms, where there are different objects (Form1,Form2 etc).
I have three different configurations on my project, all three do not require all
I have three different development machines. Do I need three different iPhone Developer Program
If I have three different tables like this table_1 Field 1: victories Field 2:
I'm playing with a GWT/GAE project which will have three different pages, although it

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.