diff --git a/views/relation_handler_endpoint_entity_join.inc b/views/relation_handler_endpoint_entity_join.inc
new file mode 100644
index 0000000..69b9931
--- /dev/null
+++ b/views/relation_handler_endpoint_entity_join.inc
@@ -0,0 +1,131 @@
+<?php
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+/**
+ * Join handler: relationship from endpoints to "right" entity.
+ */
+class relation_handler_endpoint_entity_join extends views_join{
+
+  /**
+   * Get join  condition from parent. This is not a good idea. Any better idea ?
+   *
+   * @param type $select_query
+   * @param type $table
+   * @param type $view_query
+   * @return type
+   */
+  function parent_condition($select_query, $table, $view_query)
+  {
+    if (empty($this->definition['table formula'])) {
+      $right_table = $this->table;
+    }
+    else {
+      $right_table = $this->definition['table formula'];
+    }
+
+    if ($this->left_table) {
+      $left = $view_query->get_table_info($this->left_table);
+      $left_field = "$left[alias].$this->left_field";
+    }
+    else {
+      // This can be used if left_field is a formula or something. It should be used only *very* rarely.
+      $left_field = $this->left_field;
+    }
+
+    $condition = "$left_field = $table[alias].$this->field";
+    $arguments = array();
+
+    // Tack on the extra.
+    if (isset($this->extra)) {
+      if (is_array($this->extra)) {
+        $extras = array();
+        foreach ($this->extra as $info) {
+          $extra = '';
+          // Figure out the table name. Remember, only use aliases provided
+          // if at all possible.
+          $join_table = '';
+          if (!array_key_exists('table', $info)) {
+            $join_table = $table['alias'] . '.';
+          }
+          elseif (isset($info['table'])) {
+            $join_table = $info['table'] . '.';
+          }
+
+          // Convert a single-valued array of values to the single-value case,
+          // and transform from IN() notation to = notation
+          if (is_array($info['value']) && count($info['value']) == 1) {
+            if (empty($info['operator'])) {
+              $operator = '=';
+            }
+            else {
+              $operator = $info['operator'] == 'NOT IN' ? '!=' : '=';
+            }
+            $info['value'] = array_shift($info['value']);
+          }
+
+          if (is_array($info['value'])) {
+            // With an array of values, we need multiple placeholders and the
+            // 'IN' operator is implicit.
+            foreach ($info['value'] as $value) {
+              $placeholder_i = ':views_join_condition_' . $select_query->nextPlaceholder();
+              $arguments[$placeholder_i] = $value;
+            }
+
+            $operator = !empty($info['operator']) ? $info['operator'] : 'IN';
+            $placeholder = '( ' . implode(', ', array_keys($arguments)) . ' )';
+          }
+          else {
+            // With a single value, the '=' operator is implicit.
+            $operator = !empty($info['operator']) ? $info['operator'] : '=';
+            $placeholder = ':views_join_condition_' . $select_query->nextPlaceholder();
+            $arguments[$placeholder] = $info['value'];
+          }
+
+          $extras[] = "$join_table$info[field] $operator $placeholder";
+        }
+
+        if ($extras) {
+          if (count($extras) == 1) {
+            $condition .= ' AND ' . array_shift($extras);
+          }
+          else {
+            $condition .= ' AND (' . implode(' ' . $this->extra_type . ' ', $extras) . ')';
+          }
+        }
+      }
+      elseif ($this->extra && is_string($this->extra)) {
+        $condition .= " AND ($this->extra)";
+      }
+    }
+    return $condition;
+  }
+  /**
+   * Overwrite build join method. \
+   * Add condition "Relation type"
+   *
+   * @param type $select_query
+   * @param type $table
+   * @param type $view_query
+   */
+  function build_join($select_query, $table, $view_query)
+  {
+    $conditions=$this->parent_condition($select_query, $table, $view_query);
+    // additional condition
+    //dpm($this,'this');
+    $entity_type_field_name = _field_sql_storage_columnname('endpoints', 'entity_type');
+    $entity_bundle_field_name = _field_sql_storage_columnname('endpoints', 'bundle');
+    $r_index_field_name = _field_sql_storage_columnname('endpoints', 'r_index');
+
+    $relation_type = $this->definition['relation_type'];
+    // The aliased name of the existing endpoint table we are joining to.
+    $l = $this->left_table;
+    // The aliased name of the current endpoint table.
+    $r = $table['alias'];
+    // add relation type condition
+    $conditions .= " AND $r.bundle = '$relation_type' ";
+    $select_query->addJoin($this->type, $table['table'], $table['alias'], $conditions);
+  }
+}
