@@ -3030,8 +3030,8 @@ public function getDocument(string $collection, string $id, array $queries = [],
30303030 $ collectionCacheKey = $ this ->cacheName . '-cache- ' . $ this ->getNamespace () . ': ' . $ this ->adapter ->getTenant () . ':collection: ' . $ collection ->getId ();
30313031 $ documentCacheKey = $ documentCacheHash = $ collectionCacheKey . ': ' . $ id ;
30323032
3033- if (!empty ($ selections )) {
3034- $ documentCacheHash .= ': ' . \md5 (\implode ( $ selections ));
3033+ if (!empty ($ selects )) {
3034+ $ documentCacheHash .= ': ' . \md5 (\serialize ( $ selects ));
30353035 }
30363036
30373037 try {
@@ -3081,7 +3081,7 @@ public function getDocument(string $collection, string $id, array $queries = [],
30813081 }
30823082
30833083 $ document = $ this ->casting ($ collection , $ document );
3084- $ document = $ this ->decodeV2 ($ context , $ document , $ selections );
3084+ $ document = $ this ->decodeV2 ($ context , $ document , $ selects );
30853085 $ this ->map = [];
30863086
30873087 if ($ this ->resolveRelationships && (empty ($ selects ) || !empty ($ nestedSelections ))) {
@@ -5701,12 +5701,6 @@ public function find(string $collection, array $queries = [], string $forPermiss
57015701 throw new AuthorizationException ($ authorization ->getDescription ());
57025702 }
57035703
5704- var_dump ('############ ' );
5705- var_dump ($ skipAuth );
5706- var_dump ($ forPermission );
5707- var_dump ($ _collection ->getId ());
5708- var_dump ('############ ' );
5709-
57105704 $ context ->addSkipAuth ($ this ->adapter ->filter ($ _collection ->getId ()), $ forPermission , $ skipAuth );
57115705 }
57125706
@@ -5857,11 +5851,12 @@ public function find(string $collection, array $queries = [], string $forPermiss
58575851 //$results = $skipAuth ? Authorization::skip($getResults) : $getResults();
58585852
58595853 foreach ($ results as $ index => $ node ) {
5854+ $ node = $ this ->casting ($ collection , $ node );
5855+ $ node = $ this ->decodeV2 ($ context , $ node , $ selects );
5856+
58605857 if ($ this ->resolveRelationships && (empty ($ selects ) || !empty ($ nestedSelections ))) {
58615858 $ node = $ this ->silent (fn () => $ this ->populateDocumentRelationships ($ collection , $ node , $ nestedSelections ));
58625859 }
5863- $ node = $ this ->casting ($ collection , $ node );
5864- $ node = $ this ->decode ($ collection , $ node , $ selections );
58655860
58665861 if (!$ node ->isEmpty ()) {
58675862 $ node ->setAttribute ('$collection ' , $ collection ->getId ());
@@ -6265,20 +6260,19 @@ public function decode(Document $collection, Document $document, array $selectio
62656260 * @return Document
62666261 * @throws DatabaseException
62676262 */
6268- public function decodeV2 (QueryContext $ context , Document $ document , array $ selections = []): Document
6263+ public function decodeV2 (QueryContext $ context , Document $ document , array $ selects = []): Document
62696264 {
62706265 $ schema = [];
62716266
62726267 foreach ($ context ->getCollections () as $ collection ) {
6273-
62746268 foreach ($ collection ->getAttribute ('attributes ' , []) as $ attribute ) {
62756269 $ key = $ attribute ->getAttribute ('key ' , $ attribute ->getAttribute ('$id ' ));
62766270 $ key = $ this ->adapter ->filter ($ key );
62776271 $ schema [$ collection ->getId ()][$ key ] = $ attribute ->getArrayCopy ();
62786272 }
62796273
62806274 foreach (Database::INTERNAL_ATTRIBUTES as $ attribute ) {
6281- $ schema [$ collection ->getId ()][$ attribute ['$id ' ]] = new Document ( $ attribute) ;
6275+ $ schema [$ collection ->getId ()][$ attribute ['$id ' ]] = $ attribute ;
62826276 }
62836277 }
62846278
@@ -6287,12 +6281,23 @@ public function decodeV2(QueryContext $context, Document $document, array $selec
62876281 foreach ($ document as $ key => $ value ) {
62886282 $ alias = Query::DEFAULT_ALIAS ;
62896283
6284+ foreach ($ selects as $ select ) {
6285+ if ($ this ->adapter ->filter ($ select ->getAttribute ()) == $ key ){
6286+ $ alias = $ select ->getAlias ();
6287+ break ;
6288+ }
6289+ }
6290+
62906291 $ collection = $ context ->getCollectionByAlias ($ alias );
62916292 if ($ collection ->isEmpty ()) {
62926293 throw new \Exception ('Invalid query: Unknown Alias context ' );
62936294 }
62946295
6295- $ attribute = $ schema [$ collection ->getId ()][$ key ];
6296+ $ attribute = $ schema [$ collection ->getId ()][$ key ] ?? null ;
6297+
6298+ if ($ attribute === null ){
6299+ continue ;
6300+ }
62966301
62976302 $ array = $ attribute ['array ' ] ?? false ;
62986303 $ filters = $ attribute ['filters ' ] ?? [];
@@ -6306,21 +6311,21 @@ public function decodeV2(QueryContext $context, Document $document, array $selec
63066311 }
63076312 }
63086313
6309- if (empty ($ selections ) || \in_array ($ key , $ selections ) || \in_array ('* ' , $ selections )) {
6310- if (
6311- empty ($ selections )
6312- || \in_array ($ key , $ selections )
6313- || \in_array ('* ' , $ selections )
6314- || \in_array ($ key , ['$createdAt ' , '$updatedAt ' ])
6315- ) {
6316- // Prevent null values being set for createdAt and updatedAt
6317- if (\in_array ($ key , ['$createdAt ' , '$updatedAt ' ]) && $ value [0 ] === null ) {
6318- // continue;
6319- } else {
6320- // $document->setAttribute($key, ($array) ? $value : $value[0]);
6321- }
6322- }
6323- }
6314+ // if (empty($selections) || \in_array($key, $selections) || \in_array('*', $selections)) {
6315+ // if (
6316+ // empty($selections)
6317+ // || \in_array($key, $selections)
6318+ // || \in_array('*', $selections)
6319+ // || \in_array($key, ['$createdAt', '$updatedAt'])
6320+ // ) {
6321+ // // Prevent null values being set for createdAt and updatedAt
6322+ // if (\in_array($key, ['$createdAt', '$updatedAt']) && $value[0] === null) {
6323+ // continue;
6324+ // } else {
6325+ // $document->setAttribute($key, ($array) ? $value : $value[0]);
6326+ // }
6327+ // }
6328+ // }
63246329
63256330 $ value = ($ array ) ? $ value : $ value [0 ];
63266331
@@ -6354,7 +6359,8 @@ public function casting(Document $collection, Document $document): Document
63546359 if (is_null ($ value )) {
63556360 continue ;
63566361 }
6357-
6362+ var_dump ('############# casting ' );
6363+ var_dump ($ type );
63586364 if ($ array ) {
63596365 $ value = !is_string ($ value )
63606366 ? $ value
0 commit comments