Closed (works as designed)
Project:
Migrate
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
26 Oct 2011 at 13:41 UTC
Updated:
27 Mar 2012 at 16:25 UTC
This is my migration (creating a bunch of "papers" which live in "volumes"):
class VEPaperMigration extends Migration {
public function __construct() {
parent::__construct();
$this->description = t('Migrate papers.');
$this->map = new MigrateSQLMap($this->machineName,
array(
'id' => array('type' => 'integer',
'length' => 11,
'not null' => FALSE,
'description' => 'Paper ID',
)
),
MigrateDestinationNode::getKeySchema()
);
$query = db_select('virtualexplorer.papers', 'papers')
->fields('papers', array('id', 'title'))
->condition('is_deleted', 0)
->orderBy('volume_id', 'ASC')
->orderBy('weight', 'ASC');
$this->source = new MigrateSourceSQL($query);
$this->destination = new MigrateDestinationNode('paper');
$this->addFieldMapping('title', 'title');
}
}
class VEVolumeMigration extends Migration {
public function __construct() {
parent::__construct();
$this->description = t('Migrate volumes.');
$this->dependencies = array('VEPaper', 'VEEditor');
$this->map = new MigrateSQLMap($this->machineName,
array(
'id' => array('type' => 'int',
'length' => 11,
'not null' => FALSE,
'description' => 'Volume ID',
),
),
MigrateDestinationNode::getKeySchema()
);
$query = db_select('virtualexplorer.volumes', 'volumes')
->fields('volumes', array('id', 'created', 'modified', 'published', 'is_published', 'is_doisubmitted', 'type', 'title', 'titleabbrev', 'number', 'year', 'description'));
$this->source = new MigrateSourceSQL($query);
$this->destination = new MigrateDestinationNode('volume');
$this->addFieldMapping('field_papers', 'id')->sourceMigration('VEPaper');
}
}
The migration works but field_papers, a multi-valued field, only gets referenced to a single paper instead of the multiple papers expected.
Am I doing the migration wrong or is this a feature limitation?
Comments
Comment #0.0
aidanlis commentedClean up example code.
Comment #1
drewish commentedHow would a row in VEVolumeMigration have more than one value for 'id'? Seems like you've got something setup wrong. Are papers grouped into volumes? It looks like you're trying to look up the volume id in the papers import map... Provide a little more detail on what you're actually trying to accomplish.
Comment #2
aidanlis commentedMy papers table looks like: id, volume_id, title
When my volumes get imported I want the node:volume->field_papers field to have a node reference to each of the imported papers.
I see why this is a little tricky, the relationship has gone from a one-to-many on the paper to a many-to-one on the volume. Is there a neat way to handle this?
Comment #3
aidanlis commentedI've come up with this which uses the existing mapping tables to create the relationships. It works as expected and seems like a reasonable way to proceed:
Comment #4
drewish commentedYeah sucking them in in a prepare row is the right way to gather up that info.
Comment #6
grasmash commentedI need to accomplish the same thing that you did. I currently can pass a single nid into a node reference field (field_neighborhoods), but multiple values are not working.
I've tried your method, and I've also attempted to use GROUP_CONCAT to generate a comma-separated string.
Both of these approaches work to pull data from the source as expected, but passing either an array or comma-separated string to the field mapper results in an empty field.
Any ideas or suggestions would be greatly appreciated!
I've pasted some of my code below. It's been trimmed down to show the important parts, but there may be a few extra lines that seem extraneous.
Here's my GROUP_CONCAT attempt:
Here's my prepareRow() attempt:
Thanks!
Comment #7
mikeryanI don't have time to review the whole thing there, but I would suggest checking your spelling (neighboorhoods vs. neighborhoods).
Comment #8
grasmash commentedThere was a misspelling in the old db.
Actually, I'm retrieving the data from the source without issue. The problem is that once I have the source data, I can't seem to provide it to Migrate in a format that allows multiple values to be passed.
I've edited my previous comment to cut out the slack.
:(
Comment #9
mikeryanAre the neighborhoods migrated in a previous migration process? The neighborhood nids you've set in $current_row->neighborhoods are nids from the source database, which need to be translated to their corresponding nids in the destination Drupal database:
Comment #10
jeff veit commentedMikeRyan, I just want to say thanks: it's your comment at #9 that made me realise what was missing from my import, and why it wasn't working in linking referenced nodes.
Probably something for the documentation pages - since all the examples I found assumed a nid or tid mapping without sourceMigration.
Comment #11
grasmash commentedHad forgotten about this issue! I reworked the migration with your advice and things are now working. :)
Comment #11.0
grasmash commentedAsk a question