diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index d210dc16b..8f9170fb7 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -1350,6 +1350,8 @@ public function createOrUpdateDocuments( = $document->getTenant(); } + \ksort($attributes); + $columns = []; foreach (\array_keys($attributes) as $key => $attr) { /** diff --git a/tests/e2e/Adapter/Scopes/DocumentTests.php b/tests/e2e/Adapter/Scopes/DocumentTests.php index 30fcbda9e..a4393ea0a 100644 --- a/tests/e2e/Adapter/Scopes/DocumentTests.php +++ b/tests/e2e/Adapter/Scopes/DocumentTests.php @@ -672,6 +672,38 @@ public function testUpsertDocumentsAttributeMismatch(): void $this->assertEquals(null, $existingDocument->getAttribute('last')); $this->assertEquals('second', $newDocument->getAttribute('first')); $this->assertEquals('last', $newDocument->getAttribute('last')); + + $doc3 = new Document([ + '$id' => 'third', + 'last' => 'last', + 'first' => 'third', + ]); + + $doc4 = new Document([ + '$id' => 'fourth', + 'first' => 'fourth', + 'last' => 'last', + ]); + + // Ensure mismatch of attribute orders is allowed + $docs = $database->createOrUpdateDocuments(__FUNCTION__, [ + $doc3, + $doc4 + ]); + + $this->assertEquals(2, $docs); + $this->assertEquals('third', $doc3->getAttribute('first')); + $this->assertEquals('last', $doc3->getAttribute('last')); + $this->assertEquals('fourth', $doc4->getAttribute('first')); + $this->assertEquals('last', $doc4->getAttribute('last')); + + $doc3 = $database->getDocument(__FUNCTION__, 'third'); + $doc4 = $database->getDocument(__FUNCTION__, 'fourth'); + + $this->assertEquals('third', $doc3->getAttribute('first')); + $this->assertEquals('last', $doc3->getAttribute('last')); + $this->assertEquals('fourth', $doc4->getAttribute('first')); + $this->assertEquals('last', $doc4->getAttribute('last')); } public function testUpsertDocumentsNoop(): void