Issue #2559309 by Berdir, jhedstrom: Logic error in SqlContentEntityStorage::countFieldData() drops dedicated field tables (again)

8.0.x
webchick 2015-08-28 22:58:34 -07:00
parent 44949a18f9
commit 7ea136e79c
2 changed files with 28 additions and 4 deletions

View File

@ -1634,10 +1634,12 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
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.

View File

@ -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 @@ class FieldDataCountTest extends FieldUnitTestBase {
* 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 @@ class FieldDataCountTest extends FieldUnitTestBase {
'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));
}
}