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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:23:56+00:00 2026-06-12T14:23:56+00:00

I am currently building a Rails app where a User can have many Persons

  • 0

I am currently building a Rails app where a User can have many Persons which in turn can have many Projects.

This works very well.

Now my problem is that some persons may belong to the same organisation while other persons may not belong to any organisation at all.

From what I’ve learnt so far, it would be good to move all the information pertaining the organisation into a separate table / model. (Please correct me, if I am wrong.) But what will happen then if a person does not belong to any organisation, i.e. is a private person?
How can all this be modelled in Rails?

Thanks for any help.

  • 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-12T14:23:57+00:00Added an answer on June 12, 2026 at 2:23 pm

    Is your problem simply like, You have persons that may or may not belongs to an Organization. Now how will you set it up?

    Now as you said you will move the organization related data in a separate table say organizations. And your persons(or people?) should contain a organization_id. If the person doesnt belong to any organization, then it wil be simply null. The model relationships will be somewhat like.

    class Person < AR::Base
        belongs_to :organization
    end
    
    class Organization < AR::Base
        has_many :persons #or people?
    end
    

    I skipped the relations with User and Project model here. Please let me know if I missed any part of your question.


    Update: Based on your last comment
    Lets list your scenarios:

    1. A person and organization both can have address.
    2. If a person doesnt belong to organization, then person may have his own address.
    3. If he belongs to a Organization, then his address is actually the organization’s address. Or might have own address.

    If address is the only thing repeating in person and organization, then better move it in a separate table addresses.

    Organization: has_one :address
    Person: has_one :address


    Update 2:

    Since things are a bit conditional like

    • If person belongs to organization then person.address will return the address of organization.
    • Otherwise person.address will return its own address.

    Then I would prefer the following way to keep it simple. Add a current_address (or any preferred name) method in your Person model.

    def current_address
        return organization.address if organization
        return address
    end
    

    call person.current_address instead of person.address to go through the decisions.

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

Sidebar

Related Questions

I'm building an app in Rails 3. I currently have a user model which
I'm currently building a Rails app, where a user can upload an mp3 and
I'm currently building a web app (atop Ruby on Rails), which will let users
I'm currently building my first Rails 3 app, but can't quite figure out how
I'm currently building a rails application that contains 3 user types. This is my
I am currently building a Rails app, and trying to figure out the best
When building a rails app that allows a User to login and create data,
Currently building a Rails 3 app and I've notice there are a lot of
I am building a Rails 3 app which renders different views for mobile devices
I am currently working on building an Android app for my Rails backend. I

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.