Question

I'm currently working on a migration module where I use different XML sources (supplied by external provider) to import a movie theater program. I get separate files for movies, theaters and showtimes like this (simplified):

<Movies>
 <Movie>
  <movieid>14652</movieid>
  <title>Movie Title</title>
 </Movie>
</Movies>

<Theaters>
 <Theater>
  <theaterid>75102</theaterid>
  <description>Blabla</description>
 </Theater>
</Theaters>

<Showtimes>
  <Showtime>
    <showtimeid>147001169</showtimeid>
    <movieid>14652</movieid>
    <theaterid>75102</theaterid>
    <date>2013-12-02 20:15</date>
  </Showtime>
</Showtimes>

I'm already able to import all needed data and create nodes for each type. EXCEPT the relationships between them. I'm not sure which kind of field I should use for this. Currently I'm using entity references, but I have no clue how to set them up properly and if they are the best choice for this kind of application. The plan is to display the showtime information depending on movies or theaters (e.g. show all movies currently played in selected theater or show all theaters for a given movie. Another related question. Should I overwrite the node ids (nid) with the given ids from the xml (is this save?) or shall I create different fields for them?

Thanks in advance for any help! If any more information is needed I will answer immediately ;)

Best regards, Satara


Solution

I just had to use the sourceMigration() function with the migration key defined in the 'migrations' array in the override of migrate_api() file as parameter). Now the ids get mapped properly in the entity_refernce fields:

$this->addFieldMapping('field_showtime_movie', 'movieid')->xpath('movieid')->sourceMigration('Movie');
$this->addFieldMapping('field_showtime_theater', 'theaterid')->xpath('theaterid')->sourceMigration('Theater');
Was it helpful?

Solution

If you only intend to use nodes you can also use node references: https://drupal.org/project/references

Which has been around a lot longer and maybe easier to set up. I would create a Showtime node type that has 2 x node reference fields. One to reference movies and the other to reference theaters.

Once you have created your node types you should migrate movies and theaters first and then you can reference them when migrating showtimes. You can do this when mapping the node reference fields. Migrate will map the old item id to the newly created node id. Have a look at this documentation (https://drupal.org/node/1133448) under the subheading sourceMigration.

Personally I wouldn't force the nid's. There is no need Migrate will create mapping tables so you can find out which item maps to which node anyway.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top