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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:25:51+00:00 2026-05-30T09:25:51+00:00

I am implementing two objects, say HotDog and Burger, and they are both subclass

  • 0

I am implementing two objects, say HotDog and Burger, and they are both subclass of Food.

The system I am working on will be used to create HotDog and Burger, potentially other types of Food, but never will it be used to created a generic “Food” object.

Food

class Food{
    //some fields
    protected $cooked_by;
    protected $use_before_date;
}

HotDog:

class HotDog extends Food{
    //some fields specicifc to HotDog
    private $sauage_type;
}

Burger

class Burger extends Food{
    //some fields specicifc to Burger 
    private $burger_type;
}

These models have a corresponding DB Table, namely Food, HotDog and Burger.

How if I want to select all HotDog cooked by a certain chief, currently I have to loop through every single row of HotDog like this:

SELECT food_id FROM hotdog

Then loop through the entire resultset, for each row doing:

SELECT * FROM food WHERE food_id = x AND cooked_by=chief0001

I hope you understand the structure I am trying to build here. Currently having to obtain all food_id for each HotDog row, then select from the food table one-by-one is a serious performance hit.

It would be nice to be able to just do :

SELECT * FROM hotdog WHERE cooked_by = chief0001

However as you can see, the current way of implementing the Models and the Tables does not allow me to do this. Surely I can add another column to the HotDog and Burger tables, however, should I need to query anything other than cooked_by, I will have to add yet another column to both tables.

Eventually, I will just add all the columns in the Food table into HotDog and Burger.

Is that the right way to do table inheritance ? I feel like something isn’t right here, and there should be a cleaner and better solution. However I am pulling my hair trying to come up with a good way of overcoming 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-05-30T09:25:53+00:00Added an answer on May 30, 2026 at 9:25 am

    One common solution. You have specific fields in hotdog and burger tables, and all common fields in food table. Then you just JOIN tables to get all fields. Like:

    SELECT f.*, h.* FROM food f JOIN hotdog h ON f.id = h.food_id
    WHERE f.chief_id = chief0001
    

    to get hotdogs.

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

Sidebar

Related Questions

I am implementing two processes on a LynxOS SE (POSIX conformant) system that will
I have an interface and two objects implementing that interface, massively simplied; public interface
I am currently implementing a method that accepts two bitmap objects. We can assume
Say I am implementing a view for Food. (ASP.NET MVC2) Then depending on the
I have two objects: User and Client, both implements interface IMember interface IMember {
Possible Duplicate: StructureMap singleton usage (A class implementing two interface) I'm currently designing a
So I'm implementing the repository pattern in an application and came across two issues
I am implementing slideshow. I have two options for paging between images: 1) to
I am reading a book that compares two ways of implementing threads, Middleware Threads
I'm implementing the Euclidian algorithm for finding the GCD (Greatest Common Divisor) of two

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.