For a situation where there are multiple migrations ("NewsItem", "Issue", "Person" based on D6 content type), and a content type "Video" has a nodereference field which could reference nodes for any of the first three types, how do we tell Migrate D2D to reference the correct migration?

Does this need to be handled per-row, or is it possible to say "Could be any of A, B, C"?

class MyD6VideoMigration extends MyD6Migration {
  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Related Pages
    $this->addFieldMapping('field_related_pages', 'field_related_pages')
        ->sourceMigration('Issue'); // Issue, or NewsItem, or Person?
  }
}

Turned out for me that we had a single populated reference (Issue), so didn't need to solve this question today. Asking for some future soul's benefit :)

Comments

cthos’s picture

You can actually specify the ->sourceMigration as an array, and it will loop through each of the Source Migrations until it finds a match.

So in your example it would be:

class MyD6VideoMigration extends MyD6Migration {
  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Related Pages
    $this->addFieldMapping('field_related_pages', 'field_related_pages')
        ->sourceMigration(array('Issue', 'NewsItem', 'Person')); // Issue, or NewsItem, or Person?
  }
}

It will stop at the first migration it finds with a matching destination id and return that.

cthos’s picture

Status: Active » Fixed

I've updated the migrate documentation (https://drupal.org/node/1133448) to reflect the information in this ticket.

Thanks!

xurizaemon’s picture

Much appreciated, cthos. Good to know.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

josebc’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs work

This functionality is working when using code for migration classes, however in the interface the source migration is a single value select instead of a multi, i have a migration for a lot of content types that worked perfectly from the UI except for this issue and would hate to have to re-write the whole migration in code just for this, is there a way to do that from the UI or will this require a patch?

Thank you for this great module