Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #2
DrupalDope CreditAttribution: DrupalDope commentedComment #3
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedYes there is, the Entity reference module provides 4 mapping targets for importing entity references:
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:
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.
Comment #4
DrupalDope CreditAttribution: DrupalDope commentedthank you MegaChriz, I'll try my luck!