How to migrate taxonomy with hierarchy? I'm trying to create a hierarchical taxonomy from a perpared migration database table which looks like that:

ID | NAME | PARENT
------------------
 0 | FOO  |       
 1 | BAR  |       
 2 | LORE | FOO
 3 | IPSE | FOO
 4 | DOLO | BAR


It's a pretty messy data structure, but fact is there are parent and child terms in one table.

What I did so far is migrating the parent terms first. Now my custom taxonomy looks like this:

_
|_ FOO
|_ BAR


The migration code snipped I used to achieve this works like that:

$this-&gt;addFieldMapping('name', 'PARENT');


Until now everything works as expected!



Now, in a second migration step I want to add the child terms like that to my taxonomy:

_
|_ FOO
  |_ LORE
  |_ IPSE
|_ BAR
  |_ DOLO


What I tried is to add a hierarchical mapping to my migration:

$this-&gt;addFieldMapping('name', 'NAME');
$this-&gt;addFieldMapping('parent_name', 'PARENT')
    -&gt;arguments(array('source_type' =&gt; 'name'));


But this does not work, the result is an unhierarchical list like that:

_
|_ FOO
|_ LORE
|_ IPSE
|_ BAR
|_ DOLO


Did anyone try to do something like this before? Any ideas? Thanks!
I had to migrate a nested Vocabulary from Drupal 6 to Drupal 7. My Strategy was:


Migrate the plain terms
Use the postImport() of Migrate-API to map the Parent-Relationship

public function postImport() {

// Get alle Terms from features_dd_private_contact_form_subjects
// Query zum Laden der Daten aus Drupal6
$source_query = Database::getConnection('legacy', 'legacy')
  -&gt;select('term_data', 't');

// Join Terms with voab
$source_query-&gt;join('vocabulary', 'v', 'v.vid = t.vid');

// Join Hierarchy
$source_query-&gt;join('term_hierarchy', 'th', 'th.tid = t.tid');

$source_query-&gt;condition('th.parent', '0', '&lt;&gt;');

$source_query-&gt;fields('th', array());

$source_query-&gt;condition(
  'v.module',
  'features_dd_private_contact_form_subjects',
  '='
);

$source_query-&gt;fields('t');

$source_records = $source_query-&gt;execute();

foreach ($source_records as $source_record) {


  // Term-ID in destination db.
  $dest_tid = $this-&gt;get_destination_tid_by_old_tid($source_record-&gt;tid);


  // Parent-Tid in the destination.
  $dest_parent_tid = $this-&gt;get_destination_tid_by_old_tid($source_record-&gt;parent);

  $child_term = taxonomy_term_load($dest_tid);
  $child_term-&gt;parent = $dest_parent_tid;
  taxonomy_term_save($child_term);
}


}