Migrate multiple source data rows Has anyone tried migrating fields with multiple source data rows? In my case, Im migrating values of commerce file field (https://www.drupal.org/project/commerce_file). It only migrated 1 id where it should have multiple id's. I've checked the query in the source database, it outputs correctly, my problem is upon migration.

Here's what I did.

$query-&gt;addExpression('GROUP_CONCAT(file.field_file_fid)', 'file_id');

/* … */

$this-&gt;addFieldMapping('commerce_file', 'file_id')
        -&gt;sourceMigration('PrivateFile')
        -&gt;separator(',');
$this-&gt;addFieldMapping('commerce_file:file_class')
        -&gt;defaultValue('MigrateFileFid');
$this-&gt;addFieldMapping('commerce_file:preserve_files')
        -&gt;defaultValue(1);
I found out that sourceMigration() doesn't allow multiple data source data rows (but please correct me if I'm wrong). So, I made a custom query in my prepareRow() that somehow works like sourceMigration. Here's what I did:



// group concat code
$query->addExpression('GROUP_CONCAT(file.field_file_fid)', 'file_id');

// in field mapping
$this->addFieldMapping('commerce_file', 'file_id');
$this->addFieldMapping('commerce_file:file_class')
      ->defaultValue('MigrateFileFid');

// in prepareRow()
public function prepareRow($row) {
  if (parent::prepareRow($row) === FALSE) {
    return FALSE;
  }

  // get the values of the file_id where you used group concat function
  $product_id1 = explode(",", $row->file_id); //convert csv to array
  $product_id1 = array_values($product_id1); //redeclare it to clear its index / optional
  $newsIds = array(); //array where the ids will be stored

  foreach ($product_id1 as $i) { //loop through array
      $getEquivalentId = db_select('migrate_map_privatefile', 'p') //'migrate_map_privatefile' is the migrate map table where the ids of the files are stored
              ->fields('p', array('destid1')) 
              ->condition('p.sourceid1', $i);
      $resultOfId = $getEquivalentId->execute();
      foreach ($resultOfId as $id) {
        $newsIds[] = $id->destid1; //store result to $newsIds
      }

    }

    $row->file_id = $newsIds; //the values of file_id will now be $newsIds

  }



Hope this would help someone, someday.
Cheers!