I'm working with the migrate
module for the first time and I've worked with the db_select
api a little bit, but I'm running into an error.
I'm trying to convert some old labels into a drupal taxonomy. When I browse to the /admin/content/migrate
page, it does my query correctly and shows the right number of rows that should be migrated. However, when I actually try to run the import, I get this error:
Migration failed with source plugin exception: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'labelId' in on clause is ambiguous
Here is the code I have in my LabelMigration class:
$this->map = new MigrateSQLMap($this->machineName,
array(
'labelId' => array('type' => 'int', 'not null' => TRUE)
),
MigrateDestinationTerm::getKeySchema()
);
$query = db_select('migrate_account_label', 'l')
->fields('l', array('labelId', 'label'))
;
$query->leftJoin('migrate_asset_labels_membership', 'lm', 'l.labelId = lm.labelId');
$query->leftJoin('migrate_asset', 'a', 'lm.assetId = a.assetId');
$query->addExpression('count(*)', 'num');
$query->condition('a.type', 'B');
$query->groupBy('l.labelId');
$query->groupBy('l.label');
$this->source = new MigrateSourceSQL($query);
// Set up our destination - terms in the vocabulary
$this->destination = new MigrateDestinationTerm('article_labels');
$this->addFieldMapping('name', 'label');
$this->addFieldMapping('description')
->defaultValue('');
If I remove the leftJoin()
calls then obviously the error about the on
statement goes away, but I don't understand how labelId
is ambiguous because I'm always referencing it with a table alias.
Any ideas where this error is coming from? Is it coming from the MigrateSQLMap at the top? If so, how can I reference that labelId
with an alias to make it non-ambiguous? I tried making it l.labelId
, but that didn't work.