Migrate referenced children of same content type

Let's say you have some articles with a reference field for related articles.

Here is the source content:

    -
      id: 1
      title: Article 1
      children: [2, 3]
    -
      id: 2
      title: Article 2
    -
      id: 3
      title: Article 3
    -
      id: 4
      title: Article 4
      children: [5]
    -
      id: 5
      title: Article 5

The migration will need to do a migration lookup to match the id to the imported node when it associates the related articles. We can do this in a separate migration, or all in one, because the migration_lookup plugin supports referencing itself while importing. It may temporarily create a stub for articles that have not yet been imported yet, and then import the node later when it gets to it.

Here is the rest of the migration:

status: true
id: related_articles
label: Related articles
source:
  plugin: embedded_data
  data_rows:
    -
      id: 1
      title: Article 1
      children: [2, 3]
    -
      id: 2
      title: Article 2
    -
      id: 3
      title: Article 3
    -
      id: 4
      title: Article 4
      children: [5]
    -
      id: 5
      title: Article 5
  ids:
    id:
      type: integer
  constants:
    type: article
    uid: 1
process:
  type: constants/type
  uid: constants/uid
  title: title
  field_related_articles:
    -
      plugin: skip_on_empty
      source: children
      method: process
    -
      plugin: migration_lookup
      migration: related_articles
destination:
  plugin: 'entity:node'
Tags