Migrating XML data with many-to-one relationships I'm using Drupal 8's migrate system to import data from an XML source which has this simple layout:

&lt;books&gt;
    &lt;book&gt;
        &lt;isbn&gt;...&lt;/isbn&gt;
        &lt;title&gt;...&lt;/title&gt;
        &lt;author&gt;...&lt;/author&gt;
    &lt;/book&gt;
&lt;/books&gt;


My code creates 'book' and 'author' entities on the Drupal side, with each 'book' referencing its corresponding 'author'. The problem is that different books can have the same author. This ends up creating a separate 'author' entity for every occurrence of the same author in the XML file.

I've looked at the $row variable in PrepareRow to see if there are ways of manipulating the ID map table to avoid the duplicates but haven't had any luck. So I'd appreciate any suggestions or ideas!

By the way, my code has two source plugins - one for 'author' (which runs first) and another for 'book'. I'm using the 'plugin: migration' in my YAML file to make the book entity pickup the author entity's ID. It all works except that author gets duplicated.
I ended up not using the "plugin:migration" option because apparently it assumes one-to-one relationships. So instead, I added code to the 'author' plugin's prepareRow to rejected incoming duplicate authors. Then I added code to my 'book' plugin's prepareRow to retrieve the author entity ids from the database and add it to the book entity. I was hoping for a built-in solution in the migrate system but this will do.