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
1
vote
0 answers

Doctrine2 - Class Table Inheritance

Class Table Inheritance is being used to extend Person, to allow for the addition of Employee and Dragon. A Person, Employee and Dragon can all have a Toys. How should the connection between Person, Employee, Dragon and Toys be made? The advantage…
lookbadgers
  • 988
  • 9
  • 31
1
vote
1 answer

Enforcing exclusivity in table inheritance: composite foreign key vs check constraint

I am following the technique described in Jeff Smith's "Implementing Table Inheritance in SQL Server" (which seems to be the de facto approach for implementing this kind of structure). The People base table has a 1 : 0..1 relationship with its three…
Douglas
  • 53,759
  • 13
  • 140
  • 188
1
vote
1 answer

Class Table Inheritance, repository->findByTypeId

i'm pretty new to Symfony and Doctrine and i'm facing a problem trying to set Class Table Inheritance. I have a parent Entity, called "TeamActionTarget", and 2 children called "Player" and "Competition". The model of my parent entity is the…
1
vote
1 answer

ZF2 + Doctrine2 Class Table Inherritence Excration

Im having an issue with getting my doctrine entity to extract to my ZF2 form. Im fairly new to both ZF2 and Doctrine (as well as class table inheritance). I've read through practically all of the ZF2 and Doctrine documentation, but still cant seem…
1
vote
1 answer

Multiple account-types?

I'm currently using Symfony2 and doctrine. and I'm working on a "create-account" page. There will be 2 different kinds of accounts avaliable on the page, one for normal-usersand one for companies. I've got an entity (table) called Account this table…
1
vote
1 answer

Efficient MySQL database design for categorized data

I'm a first year web development student and I'm looking for some advice on a MySQL database design in order to expand a website I recently created for an assignment. The website I'm currently developing will serve as an online database of analog…
1
vote
0 answers

Multiple Table Class Inheritence for ruby on rails

I need to set up a multiple class inheritance model here for the following models. Basically I'm building an extensible contacts directory. From a base class Contact I intend to derive other classes i.e something on the lines of : class Contact …
Ali
  • 7,353
  • 20
  • 103
  • 161
1
vote
2 answers

Inheritance mapping in NHibernate with different named Id columns

I've got three tables which share a lot of columns, so I thought to use inheritance to map them and make my data layer a bit more OOP, DRY and so on. In all of the three strategies for inheritance mapping mentioned on NHibernate manual (table per…
CMPerez
  • 905
  • 1
  • 10
  • 25
1
vote
0 answers

database design, connecting common data of different entities

We have entities like Customer, Broker, Company. These have different attributes and must be on different tables. But they can have common things, in our case Contact Info (entity->contact is one to many relationship). Whats the best way to do…
1
vote
3 answers

Table-per-Hierarchy and Future Proofing

I'm working on an application that will store "commands" in a database using NHibernate. Each command will have a set of arguments with it. For instance, the "sleep" command has a duration, and "set text" has a string value. All of these commands…
Patrick Quirk
  • 23,334
  • 2
  • 57
  • 88
1
vote
2 answers

FK column pointing to various tables

Someone suggested to me to use a table as described here in a project, and although I can't say why, I don't think it is a good idea. MyTable (MyTableId PK, Type INT NOT NULL, MyForeignKey INT NOT NULL) MyForeignKey can point to data in various…
1
vote
1 answer

Combining types table and table inheritance in Entity Framework

Lets say I have a table+class A, another table+class AType that represents different types of A, and a table+class B that inherits from A. B is a certain type of A, but it's too complex to fit with the other types of A at the data-level and needs to…
Idan Arye
  • 12,402
  • 5
  • 49
  • 68
1
vote
0 answers

stack level too deep (when changing model inheritance)

I'm trying to use the citier gem to convert some models that already exist in the following way. So far this works: Created models: Attachable < ActiveRecord::Base Link < Attachable I added acts_as_citier to both models, created and ran the…
qalep
  • 77
  • 7
1
vote
1 answer

Sqlalchemy exists with joined inheritance and Firebird

I tried to use sqlaclhemy joined table inheritance and had a strange occurrence. class CommonObject(Base): __tablename__ = "objects" id = Column("objid", Integer, primary_key=True) objname = Column(String(32)) ... class…
0
votes
2 answers

In Class Table Inheritance, how to have parent and child use the same id?

I am having two classes: Topic and Buy::Topic. The latter is a sub class of the former, through a foreign key (Buy::Topic.topic_id == Topic.id). So essentially this is using class table inheritance pattern. Buy::Topic has its own id and the foreign…