diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
index 98f4f84..7a03458 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
@@ -10,6 +10,8 @@
 use Drupal\Core\Database\Query\SelectInterface;
 use Drupal\Core\Entity\Query\QueryException;
 use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
+use Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface;
+use Drupal\Core\TypedData\DataReferenceDefinitionInterface;
 
 /**
  * Adds tables and fields to the SQL entity query.
@@ -202,17 +204,22 @@ public function addField($field, $type, $langcode) {
           $next_index_prefix = $relationship_specifier;
         }
         // Check for a valid relationship.
-        if (isset($propertyDefinitions[$relationship_specifier]) && $field_storage->getPropertyDefinition('entity')->getDataType() == 'entity_reference' ) {
-          // If it is, use the entity type.
-          $entity_type_id = $propertyDefinitions[$relationship_specifier]->getTargetDefinition()->getEntityTypeId();
-          $entity_type = $this->entityManager->getDefinition($entity_type_id);
-          $field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id);
-          // Add the new entity base table using the table and sql column.
-          $join_condition= '%alias.' . $entity_type->getKey('id') . " = $table.$sql_column";
-          $base_table = $this->sqlQuery->leftJoin($entity_type->getBaseTable(), NULL, $join_condition);
-          $propertyDefinitions = array();
-          $key++;
-          $index_prefix .= "$next_index_prefix.";
+        // Search if property is 'name' or 'name(argument)'
+        preg_match('/^([a-zA-Z_0-9]*){1}(?:\(([a-zA-Z_0-9]*)\))?$/', $relationship_specifier, $matches);
+        $property = $matches[1];
+        if (isset($propertyDefinitions[$property]) && $propertyDefinitions[$property] instanceof DataReferenceDefinitionInterface) {
+          $argument = isset($matches[2]) ? $matches[2] : NULL;
+          if (($target_definition = $propertyDefinitions[$property]->getTargetDefinition($argument)) instanceof EntityDataDefinitionInterface) {
+            $entity_type_id = $target_definition->getEntityTypeId();
+            $entity_type = $this->entityManager->getDefinition($entity_type_id);
+            $field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id);
+            // Add the new entity base table using the table and sql column.
+            $join_condition = '%alias.' . $entity_type->getKey('id') . " = $table.$sql_column";
+            $base_table = $this->sqlQuery->leftJoin($entity_type->getBaseTable(), NULL, $join_condition);
+            $propertyDefinitions = array();
+            $key++;
+            $index_prefix .= "$next_index_prefix.";
+          }
         }
         else {
           throw new QueryException(format_string('Invalid specifier @next.', array('@next' => $relationship_specifier)));
diff --git a/core/lib/Drupal/Core/TypedData/DataReferenceDefinition.php b/core/lib/Drupal/Core/TypedData/DataReferenceDefinition.php
index 23fb420..4040e5d 100644
--- a/core/lib/Drupal/Core/TypedData/DataReferenceDefinition.php
+++ b/core/lib/Drupal/Core/TypedData/DataReferenceDefinition.php
@@ -50,7 +50,7 @@ public static function createFromDataType($data_type) {
   /**
    * {@inheritdoc}
    */
-  public function getTargetDefinition() {
+  public function getTargetDefinition($argument = NULL) {
     return $this->targetDefinition;
   }
 
diff --git a/core/lib/Drupal/Core/TypedData/DataReferenceDefinitionInterface.php b/core/lib/Drupal/Core/TypedData/DataReferenceDefinitionInterface.php
index a7f2df5..207f647 100644
--- a/core/lib/Drupal/Core/TypedData/DataReferenceDefinitionInterface.php
+++ b/core/lib/Drupal/Core/TypedData/DataReferenceDefinitionInterface.php
@@ -20,9 +20,29 @@
   /**
    * Gets the data definition of the referenced data.
    *
+   * An argument can be passed to getTargetDefinition via a query:
+   * @code
+   *   $entity_ids = \Drupal::entityQuery($entity_type)
+   *     ->condition('field.property(argument).nid', 1, '=')
+   *     ->execute();
+   * @endcode
+   *
+   * Where 'property' is the name of a property found in a field type'
+   * propertyDefinitions method, which implements
+   * DataReferenceDefinitionInterface.
+   *
+   * The 'argument' string passed to this method as an argument.
+   *
+   * @param string $argument
+   *   Data passed from an entity field query hinting at which entity type to
+   *   reference.
+   *
    * @return \Drupal\Core\TypedData\DataDefinitionInterface
    *   The data definition of the referenced data.
+   *
+   * @see \Drupal\Core\Entity\Query\Sql\Tables::addField().
+   * @see \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::propertyDefinitions().
    */
-  public function getTargetDefinition();
+  public function getTargetDefinition($argument = NULL);
 
 }
