Skip to content

Commit 363ee53

Browse files
authored
Merge pull request #626 from utopia-php/cast-internals
Cast internals attributes
2 parents bfc66eb + 3d809c8 commit 363ee53

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

src/Database/Adapter/MariaDB.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
16261626
unset($results[$index]['_id']);
16271627
}
16281628
if (\array_key_exists('_tenant', $document)) {
1629-
$results[$index]['$tenant'] = $document['_tenant'] === null ? null : (int)$document['_tenant'];
1629+
$results[$index]['$tenant'] = $document['_tenant'];
16301630
unset($results[$index]['_tenant']);
16311631
}
16321632
if (\array_key_exists('_createdAt', $document)) {

src/Database/Adapter/Postgres.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
15291529
unset($results[$index]['_id']);
15301530
}
15311531
if (\array_key_exists('_tenant', $document)) {
1532-
$results[$index]['$tenant'] = $document['_tenant'] === null ? null : (int)$document['_tenant'];
1532+
$results[$index]['$tenant'] = $document['_tenant'];
15331533
unset($results[$index]['_tenant']);
15341534
}
15351535
if (\array_key_exists('_createdAt', $document)) {

src/Database/Adapter/SQL.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public function getDocument(string $collection, string $id, array $queries = [],
377377
unset($document['_uid']);
378378
}
379379
if (\array_key_exists('_tenant', $document)) {
380-
$document['$tenant'] = $document['_tenant'] === null ? null : (int)$document['_tenant'];
380+
$document['$tenant'] = $document['_tenant'];
381381
unset($document['_tenant']);
382382
}
383383
if (\array_key_exists('_createdAt', $document)) {

src/Database/Database.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3672,6 +3672,7 @@ public function createDocument(string $collection, Document $document): Document
36723672
$document = $this->silent(fn () => $this->populateDocumentRelationships($collection, $document));
36733673
}
36743674

3675+
$document = $this->casting($collection, $document);
36753676
$document = $this->decode($collection, $document);
36763677

36773678
$this->trigger(self::EVENT_DOCUMENT_CREATE, $document);
@@ -3766,6 +3767,7 @@ public function createDocuments(
37663767
$document = $this->silent(fn () => $this->populateDocumentRelationships($collection, $document));
37673768
}
37683769

3770+
$document = $this->casting($collection, $document);
37693771
$document = $this->decode($collection, $document);
37703772
$onNext && $onNext($document);
37713773
$modified++;
@@ -6482,6 +6484,8 @@ public function casting(Document $collection, Document $document): Document
64826484

64836485
$attributes = $collection->getAttribute('attributes', []);
64846486

6487+
$attributes = \array_merge($attributes, $this->getInternalAttributes());
6488+
64856489
foreach ($attributes as $attribute) {
64866490
$key = $attribute['$id'] ?? '';
64876491
$type = $attribute['type'] ?? '';

0 commit comments

Comments
 (0)