diff --git a/flag.install b/flag.install
index b49ed44..ee385ed 100644
--- a/flag.install
+++ b/flag.install
@@ -4,6 +4,8 @@
  * @file
  * Flag module install/schema/update hooks.
  */
+use Drupal\Core\Database\Database;
+use Drupal\Core\Field\BaseFieldDefinition;
 
 /**
  * Implements hook_schema().
@@ -101,3 +103,19 @@ function flag_requirements($phase) {
   */
   return $requirements;
 }
+
+/**
+ * Add new entity_id_int basefield.
+ */
+function flag_update_8000() {
+  $storage_definition = BaseFieldDefinition::create('integer')
+      ->setLabel(t('Entity ID'))
+      ->setReadOnly(TRUE)
+      ->setDescription(t('The Entity ID.'));
+
+  \Drupal::entityDefinitionUpdateManager()
+    ->installFieldStorageDefinition('entity_id_int', 'flagging', 'flag', $storage_definition);
+  Database::getConnection()->update('flagging')
+    ->expression('entity_id_int', 'entity_id')
+    ->execute();
+}
diff --git a/src/Entity/Flagging.php b/src/Entity/Flagging.php
index 8e311d9..819476d 100644
--- a/src/Entity/Flagging.php
+++ b/src/Entity/Flagging.php
@@ -129,6 +129,11 @@ class Flagging extends ContentEntityBase implements FlaggingInterface {
       ->setRequired(TRUE)
       ->setDescription(t('The Entity ID.'));
 
+    $fields['entity_id_int'] = BaseFieldDefinition::create('integer')
+      ->setLabel(t('Entity ID'))
+      ->setReadOnly(TRUE)
+      ->setDescription(t('The Entity ID.'));
+
     $fields['flagged_entity'] = BaseFieldDefinition::create('entity_reference')
       ->setLabel(t('Entity'))
       ->setDescription(t('The flagged entity.'))
@@ -181,6 +186,17 @@ class Flagging extends ContentEntityBase implements FlaggingInterface {
   }
 
   /**
+   * {@inheritdoc}
+   */
+  public function preSave(EntityStorageInterface $storage) {
+    $value = $this->entity_id->value;
+    if ((string)(int) $value === (string) $value) {
+      $this->entity_id_int->value = $value;
+    }
+    parent::preSave($storage);
+  }
+
+  /**
    * {@inheritdoc
    */
   public function postSave(EntityStorageInterface $storage, $update = TRUE) {
diff --git a/src/FlaggingViewsData.php b/src/FlaggingViewsData.php
index 32719ab..73bdbe6 100644
--- a/src/FlaggingViewsData.php
+++ b/src/FlaggingViewsData.php
@@ -7,6 +7,8 @@
 
 namespace Drupal\flag;
 
+use Drupal\Core\Entity\FieldableEntityInterface;
+use Drupal\flag\Entity\Flag;
 use Drupal\views\EntityViewsData;
 
 /**
@@ -53,6 +55,34 @@ class FlaggingViewsData extends EntityViewsData {
       ],
     ];
 
+    /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
+    $entity_field_manager = \Drupal::service('entity_field.manager');
+    $entity_type_manager = \Drupal::entityTypeManager();
+    foreach (Flag::loadMultiple(NULL) as $flag_id => $flag) {
+      /** @var \Drupal\flag\Entity\Flag $flag */
+      $entity_type = $entity_type_manager->getDefinition($flag->getFlaggableEntityTypeId());
+      $id_is_integer =
+        ($id_key = $entity_type->getKey('id')) &&
+        is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class) &&
+        $entity_field_manager->getBaseFieldDefinitions($entity_type->id())[$id_key]->getType() == 'integer';
+      $data['flagging']['flags_' . $flag_id]['relationship'] = [
+        'title' => $entity_type->getLabel(),
+        'help' => $this->t('The @entity_type this flagging belongs to..', array('@entity_type' => $entity_type->getLabel())),
+        'base' => $entity_type->getDataTable() ?: $entity_type->getBaseTable(),
+        'base field' => $entity_type->getKey('id'),
+        'relationship field' => $id_is_integer ? 'entity_id_int' : 'entity_id',
+        'id' => 'standard',
+        'label' => $entity_type->getLabel(),
+        'extra' => array(
+          array(
+            'field' => 'entity_type',
+            'value' => $entity_type->id(),
+            'table' => 'flagging'
+          ),
+        ),
+      ];
+    }
+
     return $data;
   }
 
