A helpful tip to anyone thinking of creating field collections on the fly to add to a node during a migration (using the migrate module):
Firstly, use the migrate module's prepare() method because what you need is the parent node to have already been created, and after it creates the parent node, it passes it as an object to the prepare() method automatically via the $node argument and you can use this in the setHostEntity() method - $field_collection_item->setHostEntity($this->destination->getEntityType(), $node);
Thank you this helped me out a lot.
A helpful tip to anyone thinking of creating field collections on the fly to add to a node during a migration (using the migrate module):
Firstly, use the migrate module's prepare() method because what you need is the parent node to have already been created, and after it creates the parent node, it passes it as an object to the prepare() method automatically via the $node argument and you can use this in the setHostEntity() method - $field_collection_item->setHostEntity($this->destination->getEntityType(), $node);