mardi 16 février 2016

Selecting subclass attributes with Class Table Inheritance (Table Per Type)

I have an inheritance schema that follows the Table Per Type pattern:

Harvesters  
harvester_id | description

Harvester_A  
harvester_id | propertyA_1 | propertyA_2

Harvester_B
harvester_id | propertyB_1 | propertyB_2

where Harvester_A.harvester_id and Harvester_B.harvester_id are foreign keys referencing Harvesters.harvester_id.

I have a fourth table:

Equipment_Set
equipment_set_id | ... | harvester_id

Equipment_Set.harvester_id is a foreign key to Harvesters.harvester_id.

How do I get the attributes of the specific subclass without knowing in advance which subclass I want? I.e. I have some Equipment_Set and want to get specific Harvester_A or Harvester_B attributes about its harvester_id depending on which subclass it is, but do not know in advance which one it is.

Aucun commentaire:

Enregistrer un commentaire