Skip to content

Commit

Permalink
Fix missing storeEmptyArray attribute for embed relationships in XML …
Browse files Browse the repository at this point in the history
…driver
  • Loading branch information
alcaeus committed Nov 24, 2023
1 parent 66a6f3f commit 4f7a684
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ private function addEmbedMapping(ClassMetadata $class, SimpleXMLElement $embed,
'name' => (string) $attributes['field'],
'strategy' => (string) ($attributes['strategy'] ?? $defaultStrategy),
'nullable' => isset($attributes['nullable']) ? ((string) $attributes['nullable'] === 'true') : false,
'storeEmptyArray' => isset($attributes['store-empty-array']) ? ((string) $attributes['store-empty-array'] === 'true') : false,
];
if (isset($attributes['field-name'])) {
$mapping['fieldName'] = (string) $attributes['field-name'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,17 @@ public function testShardKey(ClassMetadata $class): void
self::assertEquals(4096, $shardKey['options']['numInitialChunks'], 'Shard key option has wrong value');
}

/** @param ClassMetadata<AbstractMappingDriverUser> $class */
#[Depends('testLoadMapping')]
public function testStoreEmptyArray(ClassMetadata $class): void
{
$referenceMapping = $class->getFieldMapping('phonenumbers');
$embeddedMapping = $class->getFieldMapping('otherPhonenumbers');

self::assertFalse($referenceMapping['storeEmptyArray']);
self::assertFalse($embeddedMapping['storeEmptyArray']);
}

public function testGridFSMapping(): void
{
$class = $this->dm->getClassMetadata(AbstractMappingDriverFile::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function testDriver(): void
'isOwningSide' => true,
'nullable' => false,
'strategy' => ClassMetadata::STORAGE_STRATEGY_SET,
'storeEmptyArray' => false,
], $classMetadata->fieldMappings['address']);

self::assertEquals([
Expand All @@ -144,6 +145,7 @@ public function testDriver(): void
'isOwningSide' => true,
'nullable' => false,
'strategy' => ClassMetadata::STORAGE_STRATEGY_PUSH_ALL,
'storeEmptyArray' => false,
], $classMetadata->fieldMappings['phonenumbers']);

self::assertEquals([
Expand Down Expand Up @@ -439,6 +441,7 @@ public function testNullableFieldsMapping(): void
'isOwningSide' => true,
'nullable' => true,
'strategy' => ClassMetadata::STORAGE_STRATEGY_SET,
'storeEmptyArray' => false,
], $classMetadata->fieldMappings['address']);

self::assertEquals([
Expand All @@ -458,6 +461,7 @@ public function testNullableFieldsMapping(): void
'isOwningSide' => true,
'nullable' => true,
'strategy' => ClassMetadata::STORAGE_STRATEGY_PUSH_ALL,
'storeEmptyArray' => false,
], $classMetadata->fieldMappings['phonenumbers']);

self::assertEquals([
Expand Down

0 comments on commit 4f7a684

Please sign in to comment.