Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Alternate resources: 

Create Migrate Stubs

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:00
    Create Migrate Stubs with Joe Shindelar.
  • 0:07
    JOE SHINDELAR: In the last couple of lessons
  • 0:09
    we've been looking at creating references via a migration.
  • 0:13
    We've done a couple of things using the concept of source migrations,
  • 0:16
    allowing us to use the maps created by the migrate module
  • 0:19
    to do things like populate an entity reference
  • 0:22
    field with the appropriate node ID for a team based on the Team ID
  • 0:27
    from our source data.
  • 0:29
    Sometimes this doesn't work, though.
  • 0:32
    You can imagine the scenario where you've

Create Migrate Stubs

Loading...

The infamous causality dilemma of the chicken and the egg examines which of the two came first constantly battling with the fact that you need one to produce the other. It's a vicious circle. In this lesson we're going to explore this dilemma in the context of data migrations. Imagine a scenario where you've got an article node type that has a reference field for similar articles which you need to populate with the node ID of the similar articles. During a migration when the article is being imported the article that is being referenced may or may not exist already. If it doesn't exist already how do we know what ID we need to put into the reference field?

One option would be to solve this problem using multiple passes. A first pass that goes through and creates all the articles, and a second that comes back through and updates the similar articles field. Though what happens if the similar articles field is required? You wouldn't be able to save the article without a value in that field the first time around? So you see how this quickly becomes another example of the chicken or the egg problem?

Lucky for us the migrate module has a solution to this called stub migrations. A process that allows creating a stub or a shell for the referenced but not yet created article so that we can use it's unique ID, then when that article is encountered in the migration it will update the stub rather than create a new article.

Downloads: 
Log in or sign up to download companion files.
Additional resources: