2

I am migrating a site from one CMS to Drupal and I'm working on migrating link structures over correctly. This is something I am going to have to automate because there are over 3,500 nodes of content that I am migrating over.

I can't seem to find in Drupal 8's database schema where the relationship between parent and children nodes are stored. I have been looking for something like a 'pid' or a 'cid' column (parent id and child id, respectively), but I can't seem to find a column like that in the schema.

I know you can make nodes children of other nodes, so I know it has to store this information somewhere. If someone could tell me what table and column this information gets stored in I would greatly appreciate that.

Drupal 8 Database Schema

3

The simple answer is, there is none.

Nodes in Drupal does not have a hierarchy, it's other things on top of it that allow you to do that, depending on the use case:

Menu links: You can have menu trees and each points to a node, but the nodes themself don't really about that. Some parts might look like it does, e.g. breadcrumb but that is simply based on the path.

Book module: This allows to create a book (basically a hierarchic structure of nodes), but this only makes sense for specific cases, e.g. structured documentation that has chapters and so on.

References: In many cases, nodes are just connected between each other with reference fields, which you could make look like a hierarchy.

Taxonomy: You can have Terms with a hierarchy and reference those from nodes, but again by default that doesn't give you anything hierarchy-like unless you start to combine with with path aliases or so.

=> Content in Drupal is very different from how most other sites handle it and you can't just convert it 1:1.

2

What you are looking for is the EntityReferenceField. To understand more its behavior:

  1. Create a content type ('MyTest')
  2. Add a ContentReferenceField (EntityReferenceField on nodes). It machine name could be for example field_my_reference.
  3. Choose whatever bundle you want a reference to.
  4. Create a 'MyTest' element, and add a reference.

Now go to PHPMyAdmin or similar, and start type in the autocomplete field the following:

node__field_my_reference

Then you can see the table scheme, and how referencing in the Drupal works in general. There are two main columns:

  1. "entity_id" - that is the host entity which has the reference field
  2. And the last column of the table "..._target_id", that's the ID to which entity it is referring too

That being said, I don't recommend you to do this by "hand". I mean writing SQL queries with exact table names. Instead, use Drupal EntityTypeManager when setting up relationships between two entities (one must have of course an EntityReferenceField).

More on that, how to do that programmatically read this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.