diff --git a/src/Plugin/Deriver/TypedDataEntityRelationshipDeriver.php b/src/Plugin/Deriver/TypedDataEntityRelationshipDeriver.php
index cd2d83f..6ff0504 100644
--- a/src/Plugin/Deriver/TypedDataEntityRelationshipDeriver.php
+++ b/src/Plugin/Deriver/TypedDataEntityRelationshipDeriver.php
@@ -18,6 +18,12 @@ class TypedDataEntityRelationshipDeriver extends TypedDataRelationshipDeriver {
   protected function generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, DataDefinitionInterface $base_definition, $property_name, DataDefinitionInterface $property_definition) {
     if (method_exists($property_definition, 'getType') && $property_definition->getType() == 'entity_reference') {
       parent::generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, $base_definition, $property_name, $property_definition);
+
+      // Provide the entity type.
+      $derivative_id = $data_type_id . ':' . $property_name;
+      if (isset($this->derivatives[$derivative_id])) {
+        $this->derivatives[$derivative_id]['target_entity_type'] = $property_definition->getFieldStorageDefinition()->getPropertyDefinition('entity')->getConstraint('EntityType');
+      }
     }
   }
 
diff --git a/src/Plugin/Deriver/TypedDataRelationshipDeriver.php b/src/Plugin/Deriver/TypedDataRelationshipDeriver.php
index e0f8dbb..a0811a4 100644
--- a/src/Plugin/Deriver/TypedDataRelationshipDeriver.php
+++ b/src/Plugin/Deriver/TypedDataRelationshipDeriver.php
@@ -16,58 +16,73 @@ class TypedDataRelationshipDeriver extends TypedDataPropertyDeriverBase implemen
   protected function generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, DataDefinitionInterface $base_definition, $property_name, DataDefinitionInterface $property_definition) {
     $bundle_info = $base_definition->getConstraint('Bundle');
     // Identify base definitions that appear on bundle-able entities.
-    if ($bundle_info && array_filter($bundle_info) && $base_definition->getConstraint('EntityType')) {
-      $base_data_type =  'entity:' . $base_definition->getConstraint('EntityType');
+    if ($base_entity_type = $base_definition->getConstraint('EntityType')) {
+      if ($bundle_info && array_filter($bundle_info)) {
+        $base_data_types = [];
+        foreach ($bundle_info as $bundle) {
+          $base_data_types[] = "entity:{$base_entity_type}:{$bundle}";
+        }
+      }
+      else {
+        $base_data_types =  ["entity:{$base_entity_type}"];
+      }
     }
+
     // Otherwise, just use the raw data type identifier.
     else {
-      $base_data_type = $data_type_id;
+      $base_data_types = [$data_type_id];
     }
-    // If we've not processed this thing before.
-    if (!isset($this->derivatives[$base_data_type . ':' . $property_name])) {
-      $derivative = $base_plugin_definition;
 
-      $derivative['label'] = $this->t($this->label, [
-        '@property' => $property_definition->getLabel(),
-        '@base' => $data_type_definition['label'],
-      ]);
-      $derivative['data_type'] = $property_definition->getFieldStorageDefinition()->getPropertyDefinition($property_definition->getFieldStorageDefinition()->getMainPropertyName())->getDataType();
-      $derivative['property_name'] = $property_name;
-      $context_definition = new ContextDefinition($base_data_type, $this->typedDataManager->createDataDefinition($base_data_type));
-      // Add the constraints of the base definition to the context definition.
-      if ($base_definition->getConstraint('Bundle')) {
-        $context_definition->addConstraint('Bundle', $base_definition->getConstraint('Bundle'));
-      }
-      $derivative['context'] = [
-        'base' => $context_definition,
-      ];
-      $derivative['property_name'] = $property_name;
+    foreach ($base_data_types as $base_data_type) {
+      // If we've not processed this thing before.
+      if (!isset($this->derivatives[$base_data_type . ':' . $property_name])) {
+        $derivative = $base_plugin_definition;
 
-      $this->derivatives[$base_data_type . ':' . $property_name] = $derivative;
-    }
-    // Individual fields can be on multiple bundles.
-    elseif ($property_definition instanceof FieldConfigInterface) {
-      // We should only end up in here on entity bundles.
-      $derivative = $this->derivatives[$base_data_type . ':' . $property_name];
-      // Update label
-      /** @var \Drupal\Core\StringTranslation\TranslatableMarkup $label */
-      $label = $derivative['label'];
-      list(,, $argument_name) = explode(':', $data_type_id);
-      $arguments = $label->getArguments();
-      $arguments['@'. $argument_name] = $data_type_definition['label'];
-      $string_args = $arguments;
-      array_shift($string_args);
-      $last = array_slice($string_args, -1);
-      // The slice doesn't remove, so do that now.
-      array_pop($string_args);
-      $string = count($string_args) >= 2 ? '@property from '. implode(', ', array_keys($string_args)) .' and '. array_keys($last)[0] : '@property from @base and '. array_keys($last)[0];
-      $this->derivatives[$base_data_type . ':' . $property_name]['label'] = $this->t($string, $arguments);
-      if ($base_definition->getConstraint('Bundle')) {
-        // Add bundle constraints
-        $context_definition = $derivative['context']['base'];
-        $bundles = $context_definition->getConstraint('Bundle') ?: [];
-        $bundles = array_merge($bundles, $base_definition->getConstraint('Bundle'));
-        $context_definition->addConstraint('Bundle', $bundles);
+        $derivative['label'] = $this->t($this->label, [
+          '@property' => $property_definition->getLabel(),
+          '@base' => $data_type_definition['label'],
+        ]);
+        $main_property = $property_definition->getFieldStorageDefinition()->getPropertyDefinition($property_definition->getFieldStorageDefinition()->getMainPropertyName());
+        if ($main_property) {
+          $derivative['data_type'] = $main_property->getDataType();
+          $derivative['property_name'] = $property_name;
+          $context_definition = new ContextDefinition($base_data_type, $this->typedDataManager->createDataDefinition($base_data_type));
+          // Add the constraints of the base definition to the context definition.
+          if ($base_definition->getConstraint('Bundle')) {
+            $context_definition->addConstraint('Bundle', $base_definition->getConstraint('Bundle'));
+          }
+          $derivative['context'] = [
+            'base' => $context_definition,
+          ];
+          $derivative['property_name'] = $property_name;
+
+          $this->derivatives[$base_data_type . ':' . $property_name] = $derivative;
+        }
+      }
+      // Individual fields can be on multiple bundles.
+      elseif ($property_definition instanceof FieldConfigInterface) {
+        // We should only end up in here on entity bundles.
+        $derivative = $this->derivatives[$base_data_type . ':' . $property_name];
+        // Update label
+        /** @var \Drupal\Core\StringTranslation\TranslatableMarkup $label */
+        $label = $derivative['label'];
+        list(,, $argument_name) = explode(':', $data_type_id);
+        $arguments = $label->getArguments();
+        $arguments['@'. $argument_name] = $data_type_definition['label'];
+        $string_args = $arguments;
+        array_shift($string_args);
+        $last = array_slice($string_args, -1);
+        // The slice doesn't remove, so do that now.
+        array_pop($string_args);
+        $string = count($string_args) >= 2 ? '@property from '. implode(', ', array_keys($string_args)) .' and '. array_keys($last)[0] : '@property from @base and '. array_keys($last)[0];
+        $this->derivatives[$base_data_type . ':' . $property_name]['label'] = $this->t($string, $arguments);
+        if ($base_definition->getConstraint('Bundle')) {
+          // Add bundle constraints
+          $context_definition = $derivative['context']['base'];
+          $bundles = $context_definition->getConstraint('Bundle') ?: [];
+          $bundles = array_merge($bundles, $base_definition->getConstraint('Bundle'));
+          $context_definition->addConstraint('Bundle', $bundles);
+        }
       }
     }
   }
diff --git a/src/Plugin/Relationship/TypedDataEntityRelationship.php b/src/Plugin/Relationship/TypedDataEntityRelationship.php
index ce96841..6e04945 100644
--- a/src/Plugin/Relationship/TypedDataEntityRelationship.php
+++ b/src/Plugin/Relationship/TypedDataEntityRelationship.php
@@ -18,15 +18,17 @@ class TypedDataEntityRelationship extends TypedDataRelationship {
   public function getRelationship() {
     $plugin_definition = $this->getPluginDefinition();
 
-    $entity_type = $this->getData($this->getContext('base'))->getDataDefinition()->getSetting('target_type');
-    $context_definition = new ContextDefinition("entity:$entity_type", $plugin_definition['label']);
+    $context_definition = new ContextDefinition("entity:{$plugin_definition['target_entity_type']}", $plugin_definition['label']);
     $context_value = NULL;
 
     // If the 'base' context has a value, then get the property value to put on
     // the context (otherwise, mapping hasn't occurred yet and we just want to
     // return the context with the right definition and no value).
     if ($this->getContext('base')->hasContextValue()) {
-      $context_value = $this->getData($this->getContext('base'))->entity;
+      $data = $this->getData($this->getContext('base'));
+      if ($data) {
+        $context_value = $data->entity;
+      }
     }
 
     $context_definition->setDefaultValue($context_value);
