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

  • Home
  • SEARCH
  • 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 6597827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:15:29+00:00 2026-05-25T18:15:29+00:00

I have a 3 tables/models with the relationship illustrated below: Account | ———- |

  • 0

I have a 3 tables/models with the relationship illustrated below:

    Account
       |
   ----------
   |        |
 User     Company

They are all joined by the the Account’s PRIMARY KEY, and the User and Company each have very different sets of methods and fields.

Assuming that I only know the “account id”, and I need to load an account, I am assuming that the following is a good procedure?

  1. the Account model is loaded by id
  2. the “account type” is then determined
  3. either a User or a Company object is loaded into the Account object itself. It could be used like so:

    $account->company->company_name();

Somehow this doesn’t seem very efficient…can somebody suggest something better?

  • 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-25T18:15:30+00:00Added an answer on May 25, 2026 at 6:15 pm

    Probably best to have both User and Company extend Account, and with the parent class Account not knowing about the children classes (only the child classes should know about the parent class) so when you need to add more Account subclasses, you don’t need to change anything in Account:

        class Account {
            var $email;
            var $password;
    
            function load() {
                // load from db
            }
        }
    
        class User extends Account {
            var $first_name;
            var $last_name;
    
            function load() {
                parent::load();
                // load for this class
            }
        }
    
        class Company extends Account {
            var $company_name;
    
            function load() {
                parent::load();
                // load for this class
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, one Company and one Employee: class Company(models.Model): name = models.CharField(max_length=60)
I have two tables with a Many-To-Many relationship like this: User( emailaddress , Name)
I have three tables/models. User, Alliance and Alliance_Membership. The latter is a join table
I have three tables in my SQL 2008 database: User, CutomerUser and SalesUser. They
If i have two tables Books, CDs with corresponding models. I want to display
I have a n...n structure for two tables, makes and models . So far
I have two tables: Client(id,name,...) Purchase(id,item,date,client_id,...) They have their respective Model, with their validations.
I have two models, user and group. I also have a joining table groups_users.
I am a new guy in Ruby, and I have tables with these primary
I am learning the Model relationship types in cakephp. I have built two tables

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.