Commit 3843a79a authored by catch's avatar catch
Browse files

Issue #3189174 by tstoeckler, daffie: Entity query fails for multi-property...

Issue #3189174 by tstoeckler, daffie: Entity query fails for multi-property base fields if no property is specified

(cherry picked from commit 4a3f45ab)
parent 45c43f66
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -250,6 +250,14 @@ public function addField($field, $type, $langcode) {
            $key++;
          }
        }
        // If there are no additional specifiers but the field has a main
        // property, use that to look up the column name.
        elseif ($field_storage && $column) {
          $columns = $field_storage->getColumns();
          if (isset($columns[$column])) {
            $sql_column = $table_mapping->getFieldColumnName($field_storage, $column);
          }
        }

        $table = $this->ensureEntityTable($index_prefix, $sql_column, $type, $langcode, $base_table, $entity_id_field, $entity_tables);
      }
+20 −3
Original line number Diff line number Diff line
@@ -975,7 +975,7 @@ public function testBaseFieldMultipleColumns() {
      'name' => $this->randomMachineName(),
      'vid' => 'tags',
      'description' => [
        'value' => $this->randomString(),
        'value' => 'description1',
        'format' => 'format1',
      ],
    ]);
@@ -985,20 +985,37 @@ public function testBaseFieldMultipleColumns() {
      'name' => $this->randomMachineName(),
      'vid' => 'tags',
      'description' => [
        'value' => $this->randomString(),
        'value' => 'description2',
        'format' => 'format2',
      ],
    ]);
    $term2->save();

    // Test that the properties can be queried directly.
    $ids = $this->container->get('entity_type.manager')
      ->getStorage('taxonomy_term')
      ->getQuery()
      ->condition('description.value', 'description1')
      ->execute();
    $this->assertCount(1, $ids);
    $this->assertEquals($term1->id(), reset($ids));

    $ids = $this->container->get('entity_type.manager')
      ->getStorage('taxonomy_term')
      ->getQuery()
      ->condition('description.format', 'format1')
      ->execute();
    $this->assertCount(1, $ids);
    $this->assertEquals($term1->id(), reset($ids));

    // Test that the main property is queried if no property is specified.
    $ids = $this->container->get('entity_type.manager')
      ->getStorage('taxonomy_term')
      ->getQuery()
      ->condition('description', 'description1')
      ->execute();
    $this->assertCount(1, $ids);
    $this->assertEqual($term1->id(), reset($ids));
    $this->assertEquals($term1->id(), reset($ids));
  }

  /**