In D7 to D7 migrations, when it comes to field_collections I know “ Your field collection migration should be run after the host entity migration. ”.

I have done my host entity migration via the migrate_d2d module.

For my field_collection I have written a custom module and added migrate_d2d class name (7f4f1882cNodecook_committee_vote) as a dependency.

Has this logic flowed?

I ask because my field_collection migration does not update the previously migrated cook_committee_vote nodes, rather it makes empty stubs for them!!!

1 Answer 1


The answer is: the logic is not flowed, it is correct. when you write your own custom migration module you can establish dependencies to other migrations that you have done via code or done via UI using migrate_ui or d2d_migrate_ui modules. here is custom migration code that depends on a class generated by d2d_migrade_ui. this code worked for me:

$this->description = t('casey will migrate this field cllection even if it kills him!!!!!!'); 
// class of prviously imported node, this class name was generated by d2d_migrate module
// that is why the name is diffrent
$this->dependencies = array('7f4f1882cNodeorg_vote'); 

$query = $this->getConnection()
// start with the field that embeds the field_collection
->select('field_data_field_org_member_votes', 'nodeField')
->fields('nodeField', array('entity_id', 'field_org_member_votes_value', 'delta'))

// join it to the fields that make up the field_collection, in my case there were 3 fields
$query->leftJoin('field_data_field_org_votes_member', 'member',
'nodeField.field_org_member_votes_value = member.entity_id');
$query->addField('member', 'field_org_votes_member_nid');

$query->leftJoin('field_data_field_org_votes_vote', 'vote',
'nodeField.field_org_member_votes_value = vote.entity_id');
$query->addField('vote', 'field_org_votes_vote_value');

$query->leftJoin('field_data_field_org_votes_majority', 'majority',
'nodeField.field_org_member_votes_value = majority.entity_id');
$query->addField('majority', 'field_org_votes_majority_value');

$this->source = new MigrateSourceSQL($query);

$this->destination = new MigrateDestinationFieldCollection(
    array('host_entity_type' => 'node')

$this->map = new MigrateSQLMap($this->machineName,
        'field_org_member_votes_value' => array( 
            'type' => 'int',
            'not null' => TRUE,
            'description' => 'Unique ID for each commitee vote',
            'alias' => 'nodeField',
); //map END

$this->addFieldMapping('host_entity_id', 'entity_id') ->sourceMigration('7f4f1882cNodeorg_committee_vote');

$this->addFieldMapping('field_org_votes_member', 'field_org_votes_member') ->sourceMigration('7f4f1882cNodemember');
$this->addFieldMapping('field_org_votes_member:source_type') ->defaultValue('nid');

$this->addFieldMapping('field_org_votes_vote', 'field_org_votes_vote');

$this->addFieldMapping('field_org_votes_majority', 'field_org_votes_majority'); 

}//construct END

 function prepareRow($row) {
   // this is a good wat to test and make sure 
   // A) you have connected to the db 
   // B) you are getting proper values from your query
   // drush_print_r($row);
 }//prepareRow END
 function complete($row) {
   // drush_print_r($row);
 public function prependTextNotes($row) {
     return 'Imported notes: ' . $row;
 }//prependTextNotes   END


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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