@@ -3169,6 +3169,7 @@ public function deleteIndex(string $collection, string $id): bool
31693169 */
31703170 public function getDocument (string $ collection , string $ id , array $ queries = [], bool $ forUpdate = false ): Document
31713171 {
3172+
31723173 if ($ collection === self ::METADATA && $ id === self ::METADATA ) {
31733174 return new Document (self ::COLLECTION );
31743175 }
@@ -3319,20 +3320,6 @@ public function getDocument(string $collection, string $id, array $queries = [],
33193320 }
33203321 }
33213322
3322- // Remove internal attributes if not queried for select query
3323- // $id, $permissions and $collection are the default selected attributes for (MariaDB, MySQL, SQLite, Postgres)
3324- // All internal attributes are default selected attributes for (MongoDB)
3325- foreach ($ queries as $ query ) {
3326- if ($ query ->getMethod () === Query::TYPE_SELECT ) {
3327- $ values = $ query ->getValues ();
3328- foreach ($ this ->getInternalAttributes () as $ internalAttribute ) {
3329- if (!\in_array ($ internalAttribute ['$id ' ], $ values )) {
3330- $ document ->removeAttribute ($ internalAttribute ['$id ' ]);
3331- }
3332- }
3333- }
3334- }
3335-
33363323 $ this ->trigger (self ::EVENT_DOCUMENT_READ , $ document );
33373324
33383325 return $ document ;
@@ -6034,6 +6021,7 @@ public function find(string $collection, array $queries = [], string $forPermiss
60346021 if ($ this ->resolveRelationships && (empty ($ selects ) || !empty ($ nestedSelections ))) {
60356022 $ node = $ this ->silent (fn () => $ this ->populateDocumentRelationships ($ collection , $ node , $ nestedSelections ));
60366023 }
6024+
60376025 $ node = $ this ->casting ($ collection , $ node );
60386026 $ node = $ this ->decode ($ collection , $ node , $ selections );
60396027
@@ -6044,20 +6032,6 @@ public function find(string $collection, array $queries = [], string $forPermiss
60446032
60456033 unset($ query );
60466034
6047- // Remove internal attributes which are not queried
6048- foreach ($ queries as $ query ) {
6049- if ($ query ->getMethod () === Query::TYPE_SELECT ) {
6050- $ values = $ query ->getValues ();
6051- foreach ($ results as $ result ) {
6052- foreach ($ this ->getInternalAttributes () as $ internalAttribute ) {
6053- if (!\in_array ($ internalAttribute ['$id ' ], $ values )) {
6054- $ result ->removeAttribute ($ internalAttribute ['$id ' ]);
6055- }
6056- }
6057- }
6058- }
6059- }
6060-
60616035 $ this ->trigger (self ::EVENT_DOCUMENT_FIND , $ results );
60626036
60636037 return $ results ;
@@ -6370,20 +6344,12 @@ public function decode(Document $collection, Document $document, array $selectio
63706344 }
63716345 }
63726346
6373- if (empty ($ selections ) || \in_array ($ key , $ selections ) || \in_array ('* ' , $ selections )) {
6374- if (
6375- empty ($ selections )
6376- || \in_array ($ key , $ selections )
6377- || \in_array ('* ' , $ selections )
6378- || \in_array ($ key , ['$createdAt ' , '$updatedAt ' ])
6379- ) {
6380- // Prevent null values being set for createdAt and updatedAt
6381- if (\in_array ($ key , ['$createdAt ' , '$updatedAt ' ]) && $ value [0 ] === null ) {
6382- continue ;
6383- } else {
6384- $ document ->setAttribute ($ key , ($ array ) ? $ value : $ value [0 ]);
6385- }
6386- }
6347+ if (
6348+ empty ($ selections )
6349+ || \in_array ($ key , $ selections )
6350+ || \in_array ('* ' , $ selections )
6351+ ) {
6352+ $ document ->setAttribute ($ key , ($ array ) ? $ value : $ value [0 ]);
63876353 }
63886354 }
63896355
@@ -6565,7 +6531,7 @@ private function validateSelections(Document $collection, array $queries): array
65656531 $ selections [] = '$updatedAt ' ;
65666532 $ selections [] = '$permissions ' ;
65676533
6568- return $ selections ;
6534+ return \array_values ( \array_unique ( $ selections)) ;
65696535 }
65706536
65716537 /**
0 commit comments