Skip to content

Commit b1f51f1

Browse files
committed
Keep encode but skip default application
1 parent 939c120 commit b1f51f1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Database/Database.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5013,6 +5013,12 @@ public function updateDocuments(
50135013
$updatedAt = $updates->getUpdatedAt();
50145014
$updates['$updatedAt'] = ($updatedAt === null || !$this->preserveDates) ? DateTime::now() : $updatedAt;
50155015

5016+
$updates = $this->encode(
5017+
$collection,
5018+
$updates,
5019+
applyDefaults: false
5020+
);
5021+
50165022
// Check new document structure
50175023
$validator = new PartialStructure(
50185024
$collection,
@@ -7050,11 +7056,12 @@ public static function addFilter(string $name, callable $encode, callable $decod
70507056
*
70517057
* @param Document $collection
70527058
* @param Document $document
7059+
* @param bool $applyDefaults Whether to apply default values to null attributes
70537060
*
70547061
* @return Document
70557062
* @throws DatabaseException
70567063
*/
7057-
public function encode(Document $collection, Document $document): Document
7064+
public function encode(Document $collection, Document $document, bool $applyDefaults = true): Document
70587065
{
70597066
$attributes = $collection->getAttribute('attributes', []);
70607067
$internalDateAttributes = ['$createdAt', '$updatedAt'];
@@ -7087,6 +7094,10 @@ public function encode(Document $collection, Document $document): Document
70877094
// False positive "Call to function is_null() with mixed will always evaluate to false"
70887095
// @phpstan-ignore-next-line
70897096
if (is_null($value) && !is_null($default)) {
7097+
// Skip applying defaults during updates to avoid resetting unspecified attributes
7098+
if (!$applyDefaults) {
7099+
continue;
7100+
}
70907101
$value = ($array) ? $default : [$default];
70917102
} else {
70927103
$value = ($array) ? $value : [$value];

0 commit comments

Comments
 (0)