Questions tagged [class-table-inheritance]

Class Table Inheritance is one of several techniques for designing SQL tables in situations where subclasses that extend classes would apply if SQL had a mechanism for inheritance, which it doesn't.

SQL as such has no formal mechanism for implementing inheritance on behalf of the database builder. However, there are ways to design tables that mimic, to some extent, the behavior you would get from subclasses that extend classes in an object oriented environment.

Class Table Inheritance is one such design technique. In this technique, there is one table for the class, and one table for each distinct subclass. Columns that are relevant to all members of the class go in the class table. Columns that are only relevant to some subclasses (often only one subclass) go in the appropriate subclass table(s). The concept can easily be extended to cases where the class is itself a subclass of some even more generic superclass.

The primary key of the class table and the primary key of the subclass tables are usually shared. This is described under the tag . Implementing shared primary key involves some work on the part of the programmer, because the primary key has to be propagated from the class table to the appropriate subclass table(s) by programmed action whenever new entries are made in the class table. Shared primary keys enforce the one-to-one nature of the relationship.

A join between one of the subclass tables and the class table is simple, easy, and fast. All rows in the class table that do not pertain to the subclass at hand will drop out of the join. For convenience, these joins might be kept in defined views.

There are circumstances where the subclasses are mutually exclusive. A pet is never both a dog and a cat. There are cases where the subclasses are not mutually exclusive. One person might be both a student and an instructor at a university.

A different but simpler technique for dealing with inheritance is described under the tag .

105 questions
0
votes
1 answer

Database design for relating a table to 1 of 2 other tables

I have a database with some users and agents and want to add a simple message system. So I have the following simple set of tables: [users] - user_id (PK) [agents] - agent_id (PK) [message_threads] - message_thread_id (PK) [message] - message_id…
0
votes
1 answer

Hierarchical database model

I'm designing a classifieds website about pets that will have 3 (main) categories of ads: A- Sale B- Breeding C- Jobs The problem I'm facing is that all 3 ad categories have some things in common, but they also have some differences. For example,…
0
votes
1 answer

How to set up inheritage child entity as UserInterface with Symfony2

I have a database model with inheritage, using the "Class Table Inheritance" model of symfony2. An Employee is an abstract class, the top-level inheritance model. A Secretary is a child extending Employee. A Technician is also a child extending…
0
votes
0 answers

Class table inheritance in Yii framework using MySQL views

I would like to implement class (multi) table inheritance in Yii but i found it very difficult, so i planned to use the approach of MySQL view. Here is an example of my tables and classes: CmsAd is a table that inherits all the fields included in…
Youcef04
  • 187
  • 1
  • 3
  • 7
0
votes
2 answers

Database subtyping/supertyping

I have tables Crop, Corn, Soybean, and Grain. One entry in Crop corresponds to a single entry in one of the other tables. Crop should be one-to-one with only one of the other tables, but not more than one. The Crop table is needed because it…
jamesSampica
  • 12,230
  • 3
  • 63
  • 85
0
votes
1 answer

Doctrine Class Table Inheritance with Symfony2

I have 2 Symfony bundles. AdminBundle will always be installed. PageBundle may or may not be installed. I want to define a base Entity called AdminModule (name, controller class, description, enabled), and also a PageModule which simply inherits…
Chris
  • 1
  • 2
0
votes
1 answer

SQL Server 2008 - Is it possible to relate a primary key from one table to a generalised field in another?

I am currently working on a piece of work where I have an issue trying to relate two tables, one of which is a sub class due to generalisation. Table A has a primary key of staffID and I would like to relate this to a foreign key in a generalised…
user1919034
0
votes
2 answers

How to prevent Nhibernate from fetching derived class?

I am using Nhibernate and I have a problem when fetching a base class with multiple derived classes (each class mapping a different table). When I watch the request, Nhibernate joins on every derived tables which has a huge an impact on the…
0
votes
2 answers

Doctrine2 Inheritance and querybuilder

I'm using Inheritance with Doctrine 2.1 : Fiche is the master entity and Artist is derived from Fiche so : Fiche -> Artist then I have this method, in another repository called Abonnement : public function…
0
votes
1 answer

Ruby on Rails inheritance

I want to I achieve the following model structure in my Rails application having 3 separate tables - Value, DecimalValue and TextValue - in which DecimalValue and TextValue inherit from Value. The idea is that Value should contain only the id, and…
0
votes
2 answers

SQLAlchemy, filtering joined queries with table inheritance

First off, sorry if it turns out that what I'm trying to do is smoke crack here, I'm by no means a DB or SQLA expert. =) I have two classes, Person and Organization, that use table inheritance to inherit from Contact. ( Person.id is an fkey to…
Iain Duncan
  • 1,738
  • 16
  • 17
0
votes
1 answer

Can this entity relationship be more normalized

N Artists have M Folders. 1 Folder has N Sketches. Artist ArtistId (PK) ArtistFolder ArtistId (PK)(FK) FolderId (PK)(FK) Folder FolderId (PK) Sketch SketchId (PK) FolderId (FK) What I want now is this: 1 Artist has N Sketches. I would have to…
Pascal
  • 12,265
  • 25
  • 103
  • 195
0
votes
1 answer

Cannot insert new entity with class table inheritance (Doctrine 2.2)

I am using the class table inheritance pattern with Doctrine 2.2. My DB schema is as follows: Parent access_id (primary key) access_type (discriminator column) access_role access_acl access_primary user_id (foreign key) Child 1 access_id (foreign…
webjawns.com
  • 2,300
  • 2
  • 14
  • 34
-1
votes
2 answers

Enhanced Entity-Relationship Modeling

i have to draw Enhanced Entity-Relationship Modeling from this case : The Georgia Tech Library (GTL) has approximately 16,000 members, 100,000 titles, and 250,000 volumes (an average of 2.5 copies per book). About 10 percent of the volumes are out…
-2
votes
1 answer

Doctrine class table inheritance mapping: why a foreign key to parent table?

Short question: can I avoid generating foreign keys for inherited classes to parent classes? Can a discriminator column for inherintance mapping be set in a relation owner instead of a parent class? Explanation: I am designing a model for invoices,…
K. Weber
  • 2,643
  • 5
  • 45
  • 77
1 2 3 4 5 6
7