diff --git a/relation.module b/relation.module
index 7201071..221ec21 100644
--- a/relation.module
+++ b/relation.module
@@ -310,36 +310,42 @@ function relation_entity_delete(EntityInterface $entity) {
     relation_clear_related_entities_cache($entity->endpoints);
   }
 
-  // Delete relations to this entity.
-  $relation_ids = relation_query($entity->getEntityTypeId(), $entity->id())->execute();
-  // IDs of relations to delete.
-  $relations_to_delete = array();
-  foreach (Relation::loadMultiple($relation_ids) as $relation) {
-    // Remove any endpoints pointing to entity.
-    foreach ($relation->endpoints as $key => $endpoint) {
-      if ($endpoint->entity_id == $entity->id() && $endpoint->entity_type == $entity->getEntityTypeId()) {
-        unset($relation->endpoints[$key]);
+  // Check if there is any relation.
+  $relations_exist = \Drupal::entityTypeManager()->getStorage('relation')->getQuery()
+    ->range(0, 1)
+    ->execute();
+  if ($relations_exist) {
+    // Delete relations to this entity.
+    $relation_ids = relation_query($entity->getEntityTypeId(), $entity->id())->execute();
+    // IDs of relations to delete.
+    $relations_to_delete = array();
+    foreach (Relation::loadMultiple($relation_ids) as $relation) {
+      // Remove any endpoints pointing to entity.
+      foreach ($relation->endpoints as $key => $endpoint) {
+        if ($endpoint->entity_id == $entity->id() && $endpoint->entity_type == $entity->getEntityTypeId()) {
+          unset($relation->endpoints[$key]);
+        }
       }
-    }
 
-    // Check if relation remains valid with regards to arity.
-    $relation_type = RelationType::load($relation->bundle());
-    $arity = count($relation->endpoints);
-    if ($relation_type && ($arity < $relation_type->min_arity)) {
-      // Not valid - delete.
-      array_push($relations_to_delete, $relation->id());
+      // Check if relation remains valid with regards to arity.
+      $relation_type = RelationType::load($relation->bundle());
+      $arity = count($relation->endpoints);
+      if ($relation_type && ($arity < $relation_type->min_arity)) {
+        // Not valid - delete.
+        array_push($relations_to_delete, $relation->id());
+      }
+      else {
+        // Valid - save.
+        $relation->save();
+      }
     }
-    else {
-      // Valid - save.
-      $relation->save();
+    if (!empty($relations_to_delete)) {
+      $storage_handler = \Drupal::entityTypeManager()->getStorage('relation');
+      $relations = $storage_handler->loadMultiple($relations_to_delete);
+      $storage_handler->delete($relations);
+      \Drupal::logger('relation')->error('Relations @relations have been deleted.', array('@relations' => implode(', ', $relations_to_delete)));
     }
   }
-  if (!empty($relations_to_delete)) {
-    $storage_handler = \Drupal::entityTypeManager()->getStorage('relation');
-    $relations = $storage_handler->loadMultiple($relations_to_delete);
-    $storage_handler->delete($relations);
-    \Drupal::logger('relation')->error('Relations @relations have been deleted.', array('@relations' => implode(', ', $relations_to_delete)));
-  }
 }
 
 /**
diff --git a/src/Tests/RelationUITest.php b/src/Tests/RelationUITest.php
index 9139a97..c4aa4f4 100644
--- a/src/Tests/RelationUITest.php
+++ b/src/Tests/RelationUITest.php
@@ -4,6 +4,7 @@ namespace Drupal\relation\Tests;
 
 use Drupal\Core\Database\Database;
 use Drupal\relation\Entity\Relation;
+use Drupal\relation\Entity\RelationType;
 
 /**
  * Relation UI.
@@ -31,6 +32,7 @@ class RelationUITest extends RelationTestBase {
       'administer relation fields',
       'administer relation form display',
       'administer relation display',
+      'delete any article content',
     );
     $this->web_user = $this->drupalCreateUser($permissions);
     $this->drupalLogin($this->web_user);
@@ -61,6 +63,45 @@ class RelationUITest extends RelationTestBase {
   }
 
   /**
+   * Tests any entity delete.
+   */
+  public function testEntityDelete() {
+    // Test that there are relation types and relations created.
+    $this->assertTrue(count($this->relation_types));
+    $relation_exist = \Drupal::entityTypeManager()->getStorage('relation')->getQuery()->range(0, 1)->execute();
+    $this->assertTrue($relation_exist);
+
+    // Delete node.
+    $node = $this->node1->id();
+    $this->drupalPostForm("node/$node/delete", array(), t('Delete'));
+    // Test that there is no error thrown.
+    $this->assertText(t('The Article @label has been deleted.', ['@label' => $this->node1->label()]));
+
+    // Delete all relations and relation types.
+    foreach ($this->relation_types as $relation_type) {
+      $relation_ids = \Drupal::entityQuery('relation')->condition('relation_type', $relation_type['relation_type'], '=')->execute();
+      $type_manager = \Drupal::entityTypeManager()->getStorage('relation');
+      $relations = $type_manager->loadMultiple($relation_ids);
+      $type_manager->delete($relations);
+      $relation_type_entity = RelationType::load($relation_type['relation_type']);
+      $relation_type_entity->delete();
+      $this->assertFalse(RelationType::load($relation_type['relation_type']));
+    }
+
+    // Test that there are no relation types and relations.
+    $relation_type_exist = \Drupal::entityTypeManager()->getStorage('relation_type')->getQuery()->range(0, 1)->execute();
+    $this->assertFalse($relation_type_exist);
+    $relation_exist = \Drupal::entityTypeManager()->getStorage('relation')->getQuery()->range(0, 1)->execute();
+    $this->assertFalse($relation_exist);
+
+    // Delete another node.
+    $node = $this->node2->id();
+    $this->drupalPostForm("node/$node/delete", array(), t('Delete'));
+    // Test that there is no error thrown.
+    $this->assertText(t('The Article @label has been deleted.', ['@label' => $this->node2->label()]));
+  }
+
+  /**
    * Tests endpoint field settings.
    */
   public function testRelationEndpointsField() {
