From Wikibooks, open books for an open world
< WebObjects‎ | EOF
Jump to navigation Jump to search

Entity inheritance is a way to take advantage of the object-relational mapping layer between the EOEntity objects and the table structure in the database to provide flexibility. This flexibility can also become a source of problems, so care must be taken when using this feature. There are many tricks available from the flexibility this feature provides.

There are three kinds of entity inheritance that represent different ways to map a table or tables to an entity or entities.

Single-Table Inheritance[edit | edit source]

In single-table inheritance, a single table can be used for more than one entity. The most sure way to do this is to use a column, or a set of columns, that have ordinal values.

An example would be:

Table: Sellables
3Piper Cub500002
4Lear Jet1000002

One can create two entities. In one entity, called "Cars", the external name would be "Sellables" and there would be a restricting qualifier saying that "objType = 1". For another entity, called "Planes", the external name would also be "Sellables" and there would be a restricting qualifier saying that "objType = 2".

When instances of the Cars or the Planes entity are created, one must make sure to set the objType attribute. It is often simplest to have custom EO classes for the entities that can handle the initiation reliably.

Horizontal Inheritance[edit | edit source]

Vertical Inheritance[edit | edit source]