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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:54:45+00:00 2026-06-11T10:54:45+00:00

Consider the following example. When I write is-a, I mean a column that is

  • 0

Consider the following example. When I write “is-a”, I mean a column that is both a primary key for its table and a foreign key to another table to form a one-to-one relationship. When I write “has-a”, I mean a regular foreign key column, to form a one-to-many relationship.

  • A fruitbasket table.
  • An applebasket table, “is-a” fruitbasket.
  • An orangebasket table, “is-a” fruitbasket.
  • A fruit table, “has-a” fruitbasket.
  • An apple table, “is-a” fruit.
  • An orange table, “is-a” fruit.

Assume, for the time being, that there are context-specific columns in applebasket, orangebasket, apple and orange sufficient to warrant the existence of that table instead of cluttering the parent table with nullable columns or a type enumeration.

Questions:

  • Is it better practice to relate between fruit and fruitbasket, or to relate apple and applebasket + orange and orangebasket? The former seems less redundant, but could potentially have invalid relations (apple -> fruit -> fruitbasket -> orangebasket, for example). The latter forces the relations to be valid, but is more redundant, and requires that any other inheriting fruit table declare its own basket foreign key.
  • Specifically for PostgreSQL, given the first choice (relating fruit to fruitbasket), what is the simplest way for me to check relational validity? It would have to perform three joins.
  • Any other suggestions to implement this cleanly?

Thanks…

  • 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-11T10:54:46+00:00Added an answer on June 11, 2026 at 10:54 am

    I think you are looking at this somewhat wrong. Relational data modelling is about data while object modelling is about behavior. These are different disciplines and as much as I like to do object-relational data modelling has-a and is-a are not things that belong in the database. Instead look at functional dependencies and model them as such. Otherwise you can end up with problems if you ever have multiple apps trying to access the same data in different ways.

    For example, suppose we have two applications. One pulls data out and manipulates it, and models behavior. The second pulls data out, treats it as static, and derives information. As yourself if the LSP allows you to say “a square is-a rectangle.” In the first case, no. In the second case, yes. In the first case you might want to use a has-a “rectangular_area” and in the second case “is-a rectangle” is perfectly valid.

    So this brings me to my second point. If you are looking at this sort of complex relationship, how you do your mapping is likely to depend on what you are doing with your data. In general it is better to constrain your data based on definitional elements rather than behavioral elements. So in this case you have mappings wherever you need them. I would then suggest the following:

    1. fruit (stores apple, pear, orange, etc).
    2. any supplemental tables you need for this.
    3. fruit_basket
    4. many-many mapping table showing what kinds of fruit is in the fruit basket.

    This brings me specifically to your questions:

    Is it better practice to relate between fruit and fruitbasket, or to relate apple and applebasket + orange and orangebasket?

    Both. At the same time. See above.

    Specifically for PostgreSQL, given the first choice (relating fruit to fruitbasket), what is the simplest way for me to check relational validity?

    Declarative referential integrity will take you all the way there. Don’t be afraid to use bidirectional foreign keys with one side set to DEFERRABLE INITIALLY DEFERRED.

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

Sidebar

Related Questions

Consider the following example $q = Doctrine::getTable('User')->createQuery('u') ->where('u.username = ?', 'test'); If another related
Consider a nonlinear least squares model in R, for example of the following form):
Let's consider the following table as a toy example: id / to / status
I have a parent child relationship stored in a table consider the following example
Consider the following example program: next :: Int -> Int next i | 0
Consider the following example. I have an interface MyInterface, and then two abstract classes
Consider the following example: int size = 10, *kk = new int[size]; for (int
Consider the following example: struct Scanner { template <typename T> T get(); }; template
Consider the following example: ( live demo here ) HTML: <div class=board> <div class=row>
Please consider the following example code (from the lm doc): ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt

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.