Commit 7ea136e7 authored by webchick's avatar webchick

Issue #2559309 by Berdir, jhedstrom: Logic error in...

Issue #2559309 by Berdir, jhedstrom: Logic error in SqlContentEntityStorage::countFieldData() drops dedicated field tables (again)
parent 44949a18
......@@ -1634,10 +1634,12 @@ public function countFieldData($storage_definition, $as_bool = FALSE) {
foreach ($storage_definition->getColumns() as $column_name => $data) {
$or->isNotNull($table_mapping->getFieldColumnName($storage_definition, $column_name));
}
$query
->condition($or)
->fields('t', array('entity_id'))
->distinct(TRUE);
$query->condition($or);
if (!$as_bool) {
$query
->fields('t', array('entity_id'))
->distinct(TRUE);
}
}
elseif ($table_mapping->allowsSharedTableStorage($storage_definition)) {
// Ascertain the table this field is mapped too.
......
......@@ -8,6 +8,8 @@
namespace Drupal\field\Tests;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests counting field data records and the hasData() method on
......@@ -146,6 +148,20 @@ public function testEntityCountAndHasData() {
* Verify that we can count a table that contains an entry with index 0.
*/
public function testCountWithIndex0() {
// Create a field that will require dedicated storage.
/** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
$field_storage = FieldStorageConfig::create(array(
'field_name' => 'field_int',
'entity_type' => 'user',
'type' => 'integer',
'cardinality' => 2,
));
$field_storage->save();
FieldConfig::create(array(
'field_storage' => $field_storage,
'bundle' => 'user',
))->save();
// Create an entry for the anonymous user, who has user ID 0.
$user = $this->storageUser
->create(array(
......@@ -153,11 +169,17 @@ public function testCountWithIndex0() {
'name' => 'anonymous',
'mail' => NULL,
'status' => FALSE,
'field_int' => 42,
));
$user->save();
// Test shared table storage.
$storage = $user->getFieldDefinition('name')->getFieldStorageDefinition();
$this->assertIdentical(TRUE, $this->storageUser->countFieldData($storage, TRUE));
// Test dedicated table storage.
$storage = $user->getFieldDefinition('field_int')->getFieldStorageDefinition();
$this->assertIdentical(TRUE, $this->storageUser->countFieldData($storage, TRUE));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment