Migrating taxonomy terms when source is a separate table? I'm writing a migrator for a now-unsupported WordPress plugin that used a single "attachments" table to store data ranging from thumbnails to musical genres. It looks like this:

mysql&gt; describe attachment;
+----------------------+--------------+------+-----+---------+----------------+
| Field                | Type         | Null | Key | Default | Extra          |
+----------------------+--------------+------+-----+---------+----------------+
| attachment_id        | mediumint(7) | NO   | PRI | NULL    | auto_increment |
| attachment_target    | varchar(32)  | YES  |     | NULL    |                |
| attachment_target_id | mediumint(7) | YES  |     | 0       |                |
| attachment_type      | varchar(32)  | YES  |     | NULL    |                |
| attachment_info      | text         | YES  |     | NULL    |                |
+----------------------+--------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)


attachment_id is just an ID, attachment_target_id will correspond to a NID from the "artist" content type I'm trying to import this into, attachment_type is either "genre" or "thumbnail" and attachment_info is the actual data contained in the row ("Disco", as an example for a genre.). 

To import all the genres into a taxonomy field, it seems I would extend the class that imports all the artists from the other table, then using $this-&gt;systemOfRecord = Migration::DESTINATION, import each row into the existing nodes. Alas, given each row would be a new migration item, it seems this would overwrite the values.

I've also thought about adding a sub-query to my initial artist migration that returns a comma-separated list of genres; alas, I'm not sure how I'd do that with Drupal database abstraction layer.

Any help? Thanks!
The piece I was missing was GROUP_CONCAT for the attachment table. My query now looks like this:

$query = Database::getConnection('default', 'wp')
       -&gt;select('artists', 'a');
$query-&gt;join('attachment', 'at', 'a.artist_id = at.attachment_target_id');
$query-&gt;fields('a',
          array(
              'artist_id',
              'artist_name',
              'artist_publish_date',
              'artist_bio',
              'artist_record_company',
              'artist_social_links',
          )
        );
//Pull in genres.
$query-&gt;addExpression('GROUP_CONCAT(DISTINCT at.attachment_info)', 'genres'); 
$query-&gt;condition('at.attachment_target', 'artist');
$query-&gt;condition('at.attachment_type', 'genre');
$query-&gt;groupBy('a.artist_id');