简体   繁体   English

Drupal 8中的内容类型是否与数据库中的表相同?

[英]Are content types in Drupal 8 the same as tables in a database?

If I am creating a database and I have two tables with a many-to-many relationship, I would create a third table to represent the relationship. 如果我正在创建数据库,并且有两个表具有多对多关系,则将创建第三个表来表示该关系。

But how should I implement the above data model in Drupal 8, should I create three content types? 但是我应该如何在Drupal 8中实现上述数据模型,是否应该创建三种内容类型? so my question is, are content types in Drupal 8 the same as tables in a database, or are they something else that should be used in a different way? 所以我的问题是,Drupal 8中的内容类型是否与数据库中的表相同,还是应该以其他方式使用它们?

To store data in a custom table in Drupal 8 you're going to want to define a custom schema and expose it through a hook. 要将数据存储在Drupal 8的自定义表中,您将需要定义一个自定义架构并通过一个钩子将其公开。 Here is Acquia's documentation on that process. 这是Acquia关于该过程的文档 This is not the same as creating a content type. 这与创建内容类型不同。

Content type data is stored across several tables that are shared by other content types (such as node and node_revision ) and manipulating these tables is not easy. 内容类型数据存储在由其他内容类型(例如nodenode_revision )共享的几个表中,并且操作这些表并不容易。

The quickest way to add a content type is through the method recommended in Adding a Content Type from chapter 6 of the Drupal 8 User Guide. 添加内容类型的最快方法是通过《 Drupal 8用户指南》第6章中的“ 添加内容类型”中推荐的方法。 This allows for all the standard GUI methods for manipulating data structures. 这允许所有用于处理数据结构的标准GUI方法。

As Isaiah says, content types in Drupal are not technically the same as tables in a database as they use many tables. 正如以赛亚所说,Drupal中的内容类型在技术上与数据库中的表不同,因为它们使用许多表。 But! 但!

In your case, if you have something like table A with: 就您而言,如果您有类似表A的内容:

- name
- email
- phone
- id

And a second table, table B with: 第二张表,表B包含:

- company
- something else
- etc…
- id

and are looking at a third that would likely be something like: 并且正在寻找三分之一,可能类似于:

- id
- table A id
- table B id

Then the answer is yes . 那么答案是肯定的

In this case you would have content type A with fields for name, email, phone, and then an entity reference field pointing to content type B with the company fields. 在这种情况下,您将拥有内容类型A,其中包含用于姓名,电子邮件,电话的字段,然后是一个实体引用字段,其指向具有公司字段的内容类型B。

You can reference in any direction with the entity reference field. 您可以使用实体参考字段在任何方向上进行参考。

You might also find " Is there a way to input the data of multiple content types " helpful. 您可能还会发现“ 是否可以输入多种内容类型的数据 ”很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM