@@ -3330,20 +3330,6 @@ public function getDocument(string $collection, string $id, array $queries = [],
33303330 }
33313331 }
33323332
3333- // Remove internal attributes if not queried for select query
3334- // $id, $permissions and $collection are the default selected attributes for (MariaDB, MySQL, SQLite, Postgres)
3335- // All internal attributes are default selected attributes for (MongoDB)
3336- foreach ($ queries as $ query ) {
3337- if ($ query ->getMethod () === Query::TYPE_SELECT ) {
3338- $ values = $ query ->getValues ();
3339- foreach ($ this ->getInternalAttributes () as $ internalAttribute ) {
3340- if (!\in_array ($ internalAttribute ['$id ' ], $ values )) {
3341- $ document ->removeAttribute ($ internalAttribute ['$id ' ]);
3342- }
3343- }
3344- }
3345- }
3346-
33473333 $ this ->trigger (self ::EVENT_DOCUMENT_READ , $ document );
33483334
33493335 return $ document ;
@@ -6049,6 +6035,7 @@ public function find(string $collection, array $queries = [], string $forPermiss
60496035 if ($ this ->resolveRelationships && (empty ($ selects ) || !empty ($ nestedSelections ))) {
60506036 $ node = $ this ->silent (fn () => $ this ->populateDocumentRelationships ($ collection , $ node , $ nestedSelections ));
60516037 }
6038+
60526039 $ node = $ this ->casting ($ collection , $ node );
60536040 $ node = $ this ->decode ($ collection , $ node , $ selections );
60546041
@@ -6059,20 +6046,6 @@ public function find(string $collection, array $queries = [], string $forPermiss
60596046
60606047 unset($ query );
60616048
6062- // Remove internal attributes which are not queried
6063- foreach ($ queries as $ query ) {
6064- if ($ query ->getMethod () === Query::TYPE_SELECT ) {
6065- $ values = $ query ->getValues ();
6066- foreach ($ results as $ result ) {
6067- foreach ($ this ->getInternalAttributes () as $ internalAttribute ) {
6068- if (!\in_array ($ internalAttribute ['$id ' ], $ values )) {
6069- $ result ->removeAttribute ($ internalAttribute ['$id ' ]);
6070- }
6071- }
6072- }
6073- }
6074- }
6075-
60766049 $ this ->trigger (self ::EVENT_DOCUMENT_FIND , $ results );
60776050
60786051 return $ results ;
@@ -6385,20 +6358,12 @@ public function decode(Document $collection, Document $document, array $selectio
63856358 }
63866359 }
63876360
6388- if (empty ($ selections ) || \in_array ($ key , $ selections ) || \in_array ('* ' , $ selections )) {
6389- if (
6390- empty ($ selections )
6391- || \in_array ($ key , $ selections )
6392- || \in_array ('* ' , $ selections )
6393- || \in_array ($ key , ['$createdAt ' , '$updatedAt ' ])
6394- ) {
6395- // Prevent null values being set for createdAt and updatedAt
6396- if (\in_array ($ key , ['$createdAt ' , '$updatedAt ' ]) && $ value [0 ] === null ) {
6397- continue ;
6398- } else {
6399- $ document ->setAttribute ($ key , ($ array ) ? $ value : $ value [0 ]);
6400- }
6401- }
6361+ if (
6362+ empty ($ selections )
6363+ || \in_array ($ key , $ selections )
6364+ || \in_array ('* ' , $ selections )
6365+ ) {
6366+ $ document ->setAttribute ($ key , ($ array ) ? $ value : $ value [0 ]);
64026367 }
64036368 }
64046369
@@ -6580,7 +6545,7 @@ private function validateSelections(Document $collection, array $queries): array
65806545 $ selections [] = '$updatedAt ' ;
65816546 $ selections [] = '$permissions ' ;
65826547
6583- return $ selections ;
6548+ return \array_values ( \array_unique ( $ selections)) ;
65846549 }
65856550
65866551 /**
0 commit comments