Field API 中捆绑关系的外键?
我正在使用预先存在的数据库并迁移到 Drupal 7。 遗留数据库模型有一个公共列的基本对象表,然后是一个类型列,它指定对象是否是图像、样本、分类单元等。每个“类型”都有自己单独的列表(图像表、样本表、位置表等),使用外键绑定到基础对象表。
在某些情况下,例如图像,有一列引用样本 ID。换句话说,多个图像可以属于同一个“specimen_id”。该ID是相关样本的基础对象ID。
在迁移到 Drupal 的过程中,我为基本对象表创建了一个新实体,然后为每个基本对象“类型”定义了捆绑包。我现在在模块安装过程中将过去作为每个“类型”表一部分的列附加到捆绑包中。我通过定义字段数组和字段实例,然后循环遍历数组并调用 field_create_field()
和 field_create_instance()
来实现此目的。
这是正确的做法吗?
当我创建像specimen_id这样的外键字段时,它如何知道这是引用给定样本的基础对象实体ID?
为了建立这些关系,我实际上应该使用 hook_field_schema() 来定义它们(因为它有外键设置),然后创建字段和字段实例吗?
当然,当创建视图并需要提取信息时,这变得相关。我想它可以表述为“bundle <=>”捆绑关系。在 CRUD 操作期间,我可以在需要时使用 ids 获取所需内容。
任何帮助或见解表示赞赏。
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 setting, 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用迁移模块。
“迁移模块提供了一个灵活的框架,用于将内容从其他来源迁移到 Drupal(例如,将网站从另一个 CMS 转换到 Drupal 时)”。
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)".