开发者

Foreign key for bundle relationships in Field API?

I'm using a preexisting database and moving to 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 its 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 the 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().

Is this the correct way of doing this?

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?

In order to establish these relationships, should I actually be using hook_field_schema() to define them, as it has a foreign key sett开发者_StackOverflow社区ing, then creating the field and field instances?

Of course, this becomes relevant when creating views and needing to pull information. I guess it could be phrased as bundle <=> bundle relationships. During CRUD operations, I can get what I need when I need it using the ids.

Any help or insight is appreciated.


Use Migrate module.

"The migrate module provides a flexible framework for migrating content into Drupal from other sources (e.g., when converting a web site from another CMS to Drupal)".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜