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

Handling forms with class table inheritance models

I would like to use form_for except I have class table inheritance models using the citier gem. They are defined as such: class Fruit < ActiveRecord::Base # calories:integer # color:string end class Apple < Fruit #…
axsuul
  • 7,370
  • 9
  • 54
  • 71
0
votes
1 answer

Inheritance & Database Design

When you model inheritance through class table inheritance relationships in a database model, do you... 1) Include an attribute (boolean for two subtipes, string for more subtipes) which identifies the particular subtipe of each record? 2) Include…
User
  • 3,244
  • 8
  • 27
  • 48
0
votes
0 answers

Doctrine inheritance mapping -- add cascade on update to id field

I have set my datas with separate tables inheritance mapping, but Doctrine seems to give very limited controls about it. Among other issues, one I get is that it only cascades on DELETE. (I use XML mapping) From what I see, cascades are put inside…
Balmipour
  • 2,985
  • 1
  • 24
  • 28
0
votes
1 answer

Query on Doctrine class table inheritance with required fields

My domain has a parent IncidenceMessage class and several child classes (i.e. IncidenceMessageText). I have the following class table inheritance configuration: Domain\Model\IncidenceMessage\IncidenceMessage: type: entity repositoryClass:…
jerkan
  • 685
  • 2
  • 10
  • 28
0
votes
0 answers

Advice for MySQL schema design that supports filtering on common attributes of disparate types?

I would like to represent the following type system (this is a hierarchical type system, NOT hierarchical data) in MySQL: type A { id name } type B extends A { id name color } type C extends A { id name shape } which is…
0
votes
0 answers

Doctrine CTI eagerly load associated entities defined in a subclass of an association

I am trying to eagerly load associated entities defined in a subclass of an association (in DQL) so that this association is not lazy-loaded instead (which caused many individual queries.) Example situation Suppose I have a business with people…
Kurzyx
  • 372
  • 3
  • 14
0
votes
1 answer

ZF2 + Doctrine 2 - Child-level discriminators with Class Table Inheritance

Much asked on SO and around the web with regards to ZF2 with Doctrine 2 and using Discriminators is: how do you not declare all child Entities on the parent Entity? Especially when you have multiple modules? The short answer is: do not declare a…
rkeet
  • 3,406
  • 2
  • 23
  • 49
0
votes
1 answer

Mysql Subtype and Supertype - database modeling

I'm about to develop a personal project for learning purpose. A real-estate web site, where advertisers (registered users) can publish ads for their properties (apartments, lands, houses, ...) either for rent (for a defined period or undefined…
0
votes
1 answer

Doctrine2 Class table inheritance Entity ID

i have this situation
Jack Skeletron
  • 1,351
  • 13
  • 37
0
votes
1 answer

Sequel class table inheritance

I am hoping to start a project using Multiple/Class table inheritance in Rails. To do this i am planning to use Sequel instead of ActiveRecord. The Docs can be found here - Sequel - class table inheritance I have the Plugin working to an extent, I…
0
votes
1 answer

How do we handle database schema with artwork types which unique has data for each type?

artwork.jpg I am trying to develop an artwork solution but stuck on the category type issue on how to code this into a database schema. I just started to understand the concept of parent and foreign key. An artwork belongs to a category type like…
0
votes
1 answer

How can I delete a child table row but keep its parent in Class Table Inheritance in doctrine orm 2?

I have two entities, Item and SpecialItem SpecialItem extends Item, where Item is normal shopping item with price property, and the SpecialItem is a shopping item on sale with extra discount property. I'm using Class Table Inheritance The Item:…
Omar
  • 1
  • 4
0
votes
0 answers

Undefined method `set_primary_key' for Client

I have a problem with using Class-Table-Inheritance gem. When I try check in console the correctness of inheritance console return this error: NoMethodError: undefined method `set_primary_key' for Client (call 'Client.connection' to establish a…
0
votes
0 answers

PostgreSQL Class Inheritance Json

so with Postgres I am able to use the json-type column. So with classic relational database I use Class Table Inheritance, which seems cumberstone. Instead I can now use Postgres and just serialize my different subclasses into json and store them in…
Tim Joseph
  • 847
  • 2
  • 14
  • 28
0
votes
1 answer

How to solve multiple cascade paths?

In my database, I have a Person and Member table. The Member table has 2 foreign keys which both reference the same column in the People Table. The constraints look like this: CONSTRAINT [FK_Members_People_1] FOREIGN KEY ([PersonID]) …
Jake
  • 1,701
  • 3
  • 23
  • 44