Issue #2559309 by Berdir, jhedstrom: Logic error in SqlContentEntityStorage::countFieldData() drops dedicated field tables (again)
parent
44949a18f9
commit
7ea136e79c
|
@ -1634,10 +1634,12 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
|
||||||
foreach ($storage_definition->getColumns() as $column_name => $data) {
|
foreach ($storage_definition->getColumns() as $column_name => $data) {
|
||||||
$or->isNotNull($table_mapping->getFieldColumnName($storage_definition, $column_name));
|
$or->isNotNull($table_mapping->getFieldColumnName($storage_definition, $column_name));
|
||||||
}
|
}
|
||||||
$query
|
$query->condition($or);
|
||||||
->condition($or)
|
if (!$as_bool) {
|
||||||
->fields('t', array('entity_id'))
|
$query
|
||||||
->distinct(TRUE);
|
->fields('t', array('entity_id'))
|
||||||
|
->distinct(TRUE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elseif ($table_mapping->allowsSharedTableStorage($storage_definition)) {
|
elseif ($table_mapping->allowsSharedTableStorage($storage_definition)) {
|
||||||
// Ascertain the table this field is mapped too.
|
// Ascertain the table this field is mapped too.
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
namespace Drupal\field\Tests;
|
namespace Drupal\field\Tests;
|
||||||
|
|
||||||
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
|
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
|
* 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.
|
* Verify that we can count a table that contains an entry with index 0.
|
||||||
*/
|
*/
|
||||||
public function testCountWithIndex0() {
|
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.
|
// Create an entry for the anonymous user, who has user ID 0.
|
||||||
$user = $this->storageUser
|
$user = $this->storageUser
|
||||||
->create(array(
|
->create(array(
|
||||||
|
@ -153,11 +169,17 @@ class FieldDataCountTest extends FieldUnitTestBase {
|
||||||
'name' => 'anonymous',
|
'name' => 'anonymous',
|
||||||
'mail' => NULL,
|
'mail' => NULL,
|
||||||
'status' => FALSE,
|
'status' => FALSE,
|
||||||
|
'field_int' => 42,
|
||||||
));
|
));
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
|
// Test shared table storage.
|
||||||
$storage = $user->getFieldDefinition('name')->getFieldStorageDefinition();
|
$storage = $user->getFieldDefinition('name')->getFieldStorageDefinition();
|
||||||
$this->assertIdentical(TRUE, $this->storageUser->countFieldData($storage, TRUE));
|
$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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue