I'm using Drupal 8's migrate system to import data from an XML source which has this simple layout:
<books>
<book>
<isbn>...</isbn>
<title>...</title>
<author>...</author>
</book>
</books>
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.