I'm using a preexisting database and moving into Drupal 7.
The legacy database model has a base object table of common columns, then a type column which specifies whether the object is an image, specimen, taxon, etc. Each 'type' has it's own separate table of columns (image table, specimen table, locality table, etc.), tied to the base object table using a foreign key.
In some cases, like images, there is a column that references specimen id. In other words, several images can belong to the same "specimen_id". This id is the base object id of the related specimen.
In moving to Drupal, I created a new entity for the base object table, then defined bundles for each base object 'type'. The columns that use to be part of each 'type' table, I am now attaching to the bundles during the install of the module. I'm doing this by defining an array of fields and and field instances, then looping through the arrays and calling field_create_field() and field_create_instance().
First, is this the correct way of doing this?
Second, when I create a foreign key field like specimen_id, how does it know this is referencing the base object entity id for a given specimen?
Third, in order to establish these relationships, should I actually be using hook_field_schema() to define them, as it has a foreign key setting, then creating the field and field instances?