@@ -3649,20 +3649,8 @@ function updateAttribute(
36493649
36503650 $ cursor ->setValue ($ cursorDocument );
36513651 }
3652-
3653- $ selectQueries = [];
3654-
36553652 try {
3656- $ selectQueries = Query::groupByType ($ queries )['selections ' ] ?? [];
3657-
3658- if (! empty ($ selectQueries )) {
3659- // has selects, allow relationship on documents!
3660- $ documents = $ dbForProject ->find ('database_ ' . $ database ->getSequence () . '_collection_ ' . $ collection ->getSequence (), $ queries );
3661- } else {
3662- // has no selects, disable relationship looping on documents!
3663- $ documents = $ dbForProject ->skipRelationships (fn () => $ dbForProject ->find ('database_ ' . $ database ->getSequence () . '_collection_ ' . $ collection ->getSequence (), $ queries ));
3664- }
3665-
3653+ $ documents = $ dbForProject ->find ('database_ ' . $ database ->getSequence () . '_collection_ ' . $ collection ->getSequence (), $ queries );
36663654 $ total = $ dbForProject ->count ('database_ ' . $ database ->getSequence () . '_collection_ ' . $ collection ->getSequence (), $ queries , APP_LIMIT_COUNT );
36673655 } catch (OrderException $ e ) {
36683656 throw new Exception (Exception::DATABASE_QUERY_ORDER_NULL , "The order attribute ' {$ e ->getAttribute ()}' had a null value. Cursor pagination requires all documents order attribute values are non-null. " );
@@ -3735,41 +3723,29 @@ function updateAttribute(
37353723 ->addMetric (METRIC_DATABASES_OPERATIONS_READS , \max (1 , $ operations ))
37363724 ->addMetric (str_replace ('{databaseInternalId} ' , $ database ->getSequence (), METRIC_DATABASE_ID_OPERATIONS_READS ), \max (1 , $ operations ));
37373725
3726+ $ select = \array_reduce ($ queries , function ($ result , $ query ) {
3727+ return $ result || ($ query ->getMethod () === Query::TYPE_SELECT );
3728+ }, false );
3729+
37383730 // Check if the SELECT query includes $databaseId and $collectionId
3739- $ hasWildcard = false ;
37403731 $ hasDatabaseId = false ;
37413732 $ hasCollectionId = false ;
3742- $ hasSelectQueries = !empty ($ selectQueries );
3743-
3744- if ($ hasSelectQueries ) {
3745- foreach ($ selectQueries as $ query ) {
3746- if ($ query ->getMethod () !== Query::TYPE_SELECT ) {
3747- continue ;
3733+ if ($ select ) {
3734+ $ hasDatabaseId = \array_reduce ($ queries , function ($ result , $ query ) {
3735+ return $ result || ($ query ->getMethod () === Query::TYPE_SELECT && \in_array ('$databaseId ' , $ query ->getValues ()));
3736+ }, false );
3737+ $ hasCollectionId = \array_reduce ($ queries , function ($ result , $ query ) {
3738+ return $ result || ($ query ->getMethod () === Query::TYPE_SELECT && \in_array ('$collectionId ' , $ query ->getValues ()));
3739+ }, false );
3740+ }
3741+
3742+ if ($ select ) {
3743+ foreach ($ documents as $ document ) {
3744+ if (!$ hasDatabaseId ) {
3745+ $ document ->removeAttribute ('$databaseId ' );
37483746 }
3749-
3750- $ values = $ query ->getValues ();
3751- if (\in_array ('* ' , $ values , true )) {
3752- $ hasWildcard = true ;
3753- break ;
3754- }
3755-
3756- if (\in_array ('$databaseId ' , $ values , true )) {
3757- $ hasDatabaseId = true ;
3758- }
3759-
3760- if (\in_array ('$collectionId ' , $ values , true )) {
3761- $ hasCollectionId = true ;
3762- }
3763- }
3764-
3765- if (!$ hasWildcard ) {
3766- foreach ($ documents as $ document ) {
3767- if (!$ hasDatabaseId ) {
3768- $ document ->removeAttribute ('$databaseId ' );
3769- }
3770- if (!$ hasCollectionId ) {
3771- $ document ->removeAttribute ('$collectionId ' );
3772- }
3747+ if (!$ hasCollectionId ) {
3748+ $ document ->removeAttribute ('$collectionId ' );
37733749 }
37743750 }
37753751 }
@@ -3827,14 +3803,10 @@ function updateAttribute(
38273803 throw new Exception (Exception::GENERAL_QUERY_INVALID , $ e ->getMessage ());
38283804 }
38293805
3830- $ selects = Query::groupByType ($ queries )['selections ' ] ?? [];
3831-
3832- if (! empty ($ selects )) {
3833- // has selects, allow relationship on documents!
3806+ try {
38343807 $ document = $ dbForProject ->getDocument ('database_ ' . $ database ->getSequence () . '_collection_ ' . $ collection ->getSequence (), $ documentId , $ queries );
3835- } else {
3836- // has no selects, disable relationship looping on documents!
3837- $ document = $ dbForProject ->skipRelationships (fn () => $ dbForProject ->getDocument ('database_ ' . $ database ->getSequence () . '_collection_ ' . $ collection ->getSequence (), $ documentId , $ queries ));
3808+ } catch (QueryException $ e ) {
3809+ throw new Exception (Exception::GENERAL_QUERY_INVALID , $ e ->getMessage ());
38383810 }
38393811
38403812 if ($ document ->isEmpty ()) {
0 commit comments