I have a successful migration of content type A, B and C. In the migration of C, I have entity reference fields that get populated with the correct values coming from migration A and B.

My reference fields is a multi value node entity reference field. To prevent the values being over ridden from my previous migrations, I use the system of record method.

https://www.drupal.org/node/1117454 https://www.drupal.org/node/2550939

The example is very specific to a commerce migration.

// If "updating" a product, protect these fields.
        // We know its updating if the product exists in the database with the sku.
        // Migrate updates by deleting an entire entity and replacing with
        // the new one. We circumvent the removal of the values of these
        // fields by pulling them and overriding the defaults provided
        // in the mapping.
        // You could do the same with a nid id found with a title, or something similar.
        // $row->migrate_map_sourceid1 is usually the entity id you're looking for,
        // our example here uses a commerce_product and loads it with the provided sku
        if ($product = commerce_product_load_by_sku($row->sku)) {
            // Use the metatdata wrapper to pull values
            $product_wrapper = entity_metadata_wrapper('commerce_product', $product);

            // field_stock
            // Some products have a NULL stock, lets keep the zero default if NULL
            if ($product_wrapper->field_stock->value() !== NULL) {
                $row->stock = $product_wrapper->field_stock->value();
            } else { $row->stock = 0; }

            // field_max
            $row->max = $product_wrapper->field_max->value();

I am not sure how I would use my prepare row, current content types, their ids etc to remove the current values, update the new values, and then add the previous ones again? Or am I misunderstanding how this is suppose to work? Thanks in advance!

1 Answer 1


My solution was to use the prepare($node, stdClass $row). This basically takes the current values and joins them to the new ones.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.