Hello,
I was wondering if the feeds module supports importing related data, as in movie (=parent node) and attached reviews (=child nodes)?
From a data perspective, the child nodes (reviews) table simply contains a field referencing the parent (movie).
Is there a way to import the data into drupal while retaining the parent-child relation and create entity reference fields?
Thank you!

Comments

manarak created an issue. See original summary.

DrupalDope’s picture

Issue summary: View changes
MegaChriz’s picture

Component: Feeds Import (feature) » Documentation
Category: Feature request » Support request
Status: Active » Fixed

Yes there is, the Entity reference module provides 4 mapping targets for importing entity references:

  • Entity reference by Feeds GUID
  • Entity reference by Feeds URL
  • Entity reference by Entity ID
  • Entity reference by Entity label

The important thing is that the parent data is imported first and then the child data. If the child data is imported first then importing the reference will fail as the reference does not exist yet. Should you not be able to avoid this situation, then running the import a second time will fix this (as then the referenced data would exist).

In case of movies and reviews as in your example you would need to do the following:

  1. Create an importer for importing the movies. Map the unique ID of the movie to "GUID". Also, mark this target as unique.
  2. Create an importer for importing the reviews. Map the movie ID to "Entity reference by Feeds GUID".
  3. Run the movie importer.
  4. Run the reviews importer.

An other important thing to note when using the steps above is that the ID of the movie must be really globally unique (thus the same ID's must not be in use by other items that you import). If there is overlap in GUIDs across multiple importers, the wrong references may be imported. Should this be the case, then there is an easy fix: use the Feeds Tamper plugin "Rewrite" to add a prefix to the movie ID's. You will need to add this tamper plugin to "GUID" for the movie importer and to "Entity reference by Feeds GUID" for the reviews importer.
To prefix the movie ID with "movie_", use something like this as the "Replacement pattern" for the Rewrite tamper:
movie_[movie_id]

For importing complex relational data, the Migrate module is a better choice, as that module supports importing relational data much better than Feeds does. For example, Migrate figures out itself in which order the data must be imported, so references can be imported successfully. If I remember well, it could also fill up the references later should they not yet exist when processing a particular item.
The downside of Migrate compared to Feeds in my opinion is that Migrate can be a lot harder to setup correctly. Therefore, for importing simple data structures I prefer Feeds.

DrupalDope’s picture

thank you MegaChriz, I'll try my luck!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.