Tagged ids for table-per-class
If SmallPublisher extends Publisher
, modeled as two small_publishers
and publishers
tables, what should the tagged id be of smallPublisher.id
?
- Same tag across all subtypes
- Pro: can avoid teaching
sameEntity
thatp:1
===sp:1
- Con: cannot know, when creating a tag for a FK, which type to use; does the
publisher_id=1
point to aLargePublisher
orSmallPublisher
? Should the key besp:1
orlp:1
? We can't know w/o probing the type. - Con: Having
p:1
doesn't guarantee the constructor isPublisher
, it could beSmallPublisher
- Pro: can avoid teaching
- Per-subtype tags
- Pro: Neat to just glance at an id and know the subtype
- Pro: Keeps tag -> correct constructor convention
- Con: Foreign keys would need to support either
sp:1
orlp:1
runtime tag checks - Con: Complicates
sameEntity
for tag values ofp:1
andsp:1
- Subdivide the keyspace by type, odds are small publishers, even are large publishers
- Con: Only works when knowing the number of subtypes up-front. Recoding would be impossible.
- Add an extra
kind
column to the base table that is the subtype+id likekind=sp:1
. FKs go the kind.