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
3
votes
2 answers

Cascading Delete in Class Table Inheritance doesn't delete parent row

I have a parent class called Notification, that has CommentNotification as one of it's children (Class table inheritance). /** * This entity represents the notifications that are sent to users when an event happens *…
IT-Girl
  • 448
  • 5
  • 24
3
votes
2 answers

CakePHP alternative to Class Table Inheritance?

I want to create a Class Table Inheritance model in CakePHP. I would like to have a Model called something like ProductBase with the table product_bases to hold all the base information every product should have, like upc, price, etc. Then have…
JD Isaacks
  • 56,088
  • 93
  • 276
  • 422
3
votes
2 answers

Best approach to implement inheritance in a data warehouse based on a postgres database

I am developing a multi-step data pipeline that should optimize the following process: 1) Extract data from a NoSQL database (MongoDB). 2) Transform and load the data into a relational (PostgreSQL) database. 3) Build a data warehouse using the…
3
votes
0 answers

Use both Class Table and Single Table inheritance in Castle Activerecord?

In Castle Activerecord (on top of NHibernate), is it possible to use class table inheritance globally, and single table inheritance on part of the inheritance tree? I would like to do something like /// /// Base class for models ///…
3
votes
1 answer

Doctrine 2 Class Table Inheritance YML

I'm trying to use Class Table Inheritance within ZF2 and Doctrine 2. My implementation is pretty simple. I think I have the class structure all set, but I think there might be a problem with some setup somewhere. Unfortunately, I have found a lot…
3
votes
5 answers

Database design for 2 types of users

I have 2 ways for users to create an account on my website. a. Normal Registration Form (email, password) b. Registration via Facebook Connect (fb_userid, email) Which is the best practice to implement this using MySQL (InnoDB engine) ? My…
2
votes
1 answer

Class Table Inheritance (CTI) and Insert Select statements

I am working to build an inheritance database model within MySQL, such that all tables inherit from one base type (object), represented by the object table. This allows for Notes to be linked to any object from any table within the database while…
therealmitchconnors
  • 2,732
  • 1
  • 18
  • 36
2
votes
1 answer

Zend Framework 1.11 + Doctrine 2 + Class Inheritance mapping (YAML) problems with generate entities

I get number of problems trying to implement CTI First of all I use a custom loader for my entity classes class My_AutoLoader implements Zend_Loader_Autoloader_Interface { public function autoload($class) { $class =…
venimus
  • 5,907
  • 2
  • 28
  • 38
2
votes
1 answer

"Unable to generate an IRI" error in Api Platform when Many-To-Many, Self-referencing relation is present in abstract superclass Entity

I have an abstract entity "Node" superclass, with the following code that is the base for four other entities subclasses. I want to nest them in any order to create a loose hierarchy where any kind of node can be parent or child of any other type,…
2
votes
3 answers

Rails class-table inheritance gem, faux-inheritance, and missing methods

I'm working on modifying part of an existing Rails app to use the Class-Table-Inheritance gem (https://github.com/brunofrank/class-table-inheritance). All's well, except that I have defined some instance methods in my superclass -- Person, which…
Alterscape
  • 1,526
  • 1
  • 17
  • 34
2
votes
1 answer

How to setup Class Table Inheritance to tables with different ID-columns' names in Doctrine 2?

I have a table person with id as identifier column and a tables student with person_id as PRIMARY KEY. The column student.person_id references (FOREIGN KEY) the person.id. There are accordingly three classes: An abstract class Person with a member…
automatix
  • 14,018
  • 26
  • 105
  • 230
2
votes
0 answers

What are the possible solutions to OO/Table inheritance (ie. STI,MTI,CLI) in Rails 5+?

These are the options I see that can help solve "Rails 5 - Object Relation Impedence and how to structure multiple inherited classes/tables" TL;DR - the Object Table Impedance ORM problem. Abstract base class, with each child class having its own…
2
votes
1 answer

No implicit conversion of nil into String. dbview_cti

I use dbview_cti gem to make Class Table Inheritance (CTI). I have two classes Person(abstract class) and Client(inherits Person). Problem: When I try make rake db:migrate, console write this error: StandardError: An error has occurred, this and all…
2
votes
0 answers

Entity Framework TPT Inheritance with ObjectType Discriminator Column

I'm using Entity Framework as an ORM for my database. To model inheritance, my database uses the Table Per Type (aka Class Table Inheritance) pattern. Entity Framework does support TPT inheritance. However it is extremely slow. It generates very…
2
votes
2 answers

Should I make 1 or 2 tables for Lecturers and Students in MySql?

I am currently working on a project where you save the details of a lecturer and student. I am not sure if I should use one table User or two tables Lecturer and Student. When you log in as a lecturer you have special privileges as its a group…