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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:01:39+00:00 2026-05-24T12:01:39+00:00

For a CRM app, I want to be able to associate a Person model

  • 0

For a CRM app, I want to be able to associate a Person model directly to an Account model or to a Company model which in turn is associated to an Account model. Also, I want to associate an Address model to either a Company or a Person. This is what I have in mind:

class Account
    has_many :Persons
    has_many :Companies
end

class Person
    belongs_to :Account
    belongs_to :Company
    has_one :Address
end

class Company
    belongs_to :Account
    has_many :Persons
    has_one :Address
end

class Address
    belongs_to :Person
    belongs_to :Company
end

So an Account would be either a “person account” or a “business account” depending on the association. They would be mutually exclusive. I plan to have the foreign keys account_id and company_id in the Person table. By the same token I would have the foreign keys person_id and company_id in the Address table. One foreign key would be null in each case.

Is this okay in Rails? If not, any recommendations would be greatly appreciated.

  • 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-24T12:01:40+00:00Added an answer on May 24, 2026 at 12:01 pm

    Take a look at polymorphic associations. I think that’s what you are looking for:
    http://guides.rubyonrails.org/association_basics.html#polymorphic-associations

    class Account
         belongs_to :User, :polymorphic => true
    end
    
    class Person
         belongs_to :Account, :as => :User
         belongs_to :Company
         has_one :Address, :as => :User
    end
    
    class Company
         belongs_to :Account, :as => :User
         belongs_to :Persons
         has_one :Address, :as => :User
    end
    
    class Address
         belongs_to :User, :polymorphic => true
    end
    ...
    

    Greetings Sven

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

Sidebar

Related Questions

I am working on a CRM app in android, in which, I am showing
I'm want to create a CRM app for me just for fun and to
we are developing a CRM app which holds customer meeting info. Users have requested
I want to develop a CRM iphone app. I think there are 2 methods
I'm working on an in-house Rails app, which is (among other things) a CRM
I have a local windows app written in java, kind of crm. Employees register
My company has a CRM site hosted externally on a shared server and recently
i trying to add some costume app into Dynamics CRM basically i have an
How can I run an ASP.net 4.0 app in the ISV folder on CRM
I'm writing application, which connects to CRM using CRM SDK 4. In the first

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.