@@ -3296,7 +3296,7 @@ public function getDocument(string $collection, string $id, array $queries = [],
32963296 if ($ collection ->getId () !== self ::METADATA ) {
32973297 if (!$ validator ->isValid ([
32983298 ...$ collection ->getRead (),
3299- ...($ documentSecurity ? $ document ->getRead () : [])
3299+ ...($ documentSecurity ? $ document ->getRead (' main::$permissions ' ) : [])
33003300 ])) {
33013301 return new Document ();
33023302 }
@@ -3323,7 +3323,7 @@ public function getDocument(string $collection, string $id, array $queries = [],
33233323 if ($ collection ->getId () !== self ::METADATA ) {
33243324 if (!$ validator ->isValid ([
33253325 ...$ collection ->getRead (),
3326- ...($ documentSecurity ? $ document ->getRead () : [])
3326+ ...($ documentSecurity ? $ document ->getRead (' main::$permissions ' ) : [])
33273327 ])) {
33283328 return new Document ();
33293329 }
@@ -3686,6 +3686,13 @@ public function createDocument(string $collection, Document $document): Document
36863686
36873687 $ this ->trigger (self ::EVENT_DOCUMENT_CREATE , $ document );
36883688
3689+ $ document ->setAttribute ('main::$id ' , $ document ->getId ());
3690+ $ document ->setAttribute ('main::$sequence ' , $ document ->getSequence ());
3691+ $ document ->setAttribute ('main::$permissions ' , $ document ->getPermissions ());
3692+ $ document ->setAttribute ('main::$createdAt ' , $ document ->getCreatedAt ());
3693+ $ document ->setAttribute ('main::$updatedAt ' , $ document ->getUpdatedAt ());
3694+ $ document ->setAttribute ('main::$tenant ' , $ document ->getTenant ());
3695+
36893696 return $ document ;
36903697 }
36913698
@@ -4133,6 +4140,10 @@ public function updateDocument(string $collection, string $id, Document $documen
41334140
41344141 $ document = $ this ->withTransaction (function () use ($ collection , $ id , $ document ) {
41354142 $ time = DateTime::now ();
4143+
4144+ /**
4145+ * @var $old Document
4146+ */
41364147 $ old = Authorization::skip (fn () => $ this ->silent (
41374148 fn () => $ this ->getDocument ($ collection ->getId (), $ id , forUpdate: true )
41384149 ));
@@ -4162,8 +4173,14 @@ public function updateDocument(string $collection, string $id, Document $documen
41624173 $ relationships [$ relationship ->getAttribute ('key ' )] = $ relationship ;
41634174 }
41644175
4176+ $ alias = Query::DEFAULT_ALIAS ;
4177+
41654178 // Compare if the document has any changes
41664179 foreach ($ document as $ key => $ value ) {
4180+ if (str_starts_with ($ key , $ alias .':: ' ) && Database::isInternalAttribute ($ key )){
4181+ continue ;
4182+ }
4183+
41674184 // Skip the nested documents as they will be checked later in recursions.
41684185 if (\array_key_exists ($ key , $ relationships )) {
41694186 // No need to compare nested documents more than max depth.
@@ -4211,6 +4228,9 @@ public function updateDocument(string $collection, string $id, Document $documen
42114228
42124229 if (\count ($ old ->getAttribute ($ key )) !== \count ($ value )) {
42134230 $ shouldUpdate = true ;
4231+ var_dump ('$shouldUpdate 1 ' );
4232+ var_dump ($ shouldUpdate );
4233+
42144234 break ;
42154235 }
42164236
@@ -4224,6 +4244,8 @@ public function updateDocument(string $collection, string $id, Document $documen
42244244 ($ relation instanceof Document && $ relation ->getId () !== $ oldValue )
42254245 ) {
42264246 $ shouldUpdate = true ;
4247+ var_dump ('$shouldUpdate 2 ' );
4248+ var_dump ($ shouldUpdate );
42274249 break ;
42284250 }
42294251 }
@@ -4307,6 +4329,16 @@ public function updateDocument(string $collection, string $id, Document $documen
43074329
43084330 $ this ->trigger (self ::EVENT_DOCUMENT_UPDATE , $ document );
43094331
4332+ /**
4333+ * Make this smarter
4334+ */
4335+ $ document ->setAttribute ('main::$id ' , $ document ->getId ());
4336+ $ document ->setAttribute ('main::$sequence ' , $ document ->getSequence ());
4337+ $ document ->setAttribute ('main::$permissions ' , $ document ->getPermissions ());
4338+ $ document ->setAttribute ('main::$createdAt ' , $ document ->getCreatedAt ());
4339+ $ document ->setAttribute ('main::$updatedAt ' , $ document ->getUpdatedAt ());
4340+ $ document ->setAttribute ('main::$tenant ' , $ document ->getTenant ());
4341+
43104342 return $ document ;
43114343 }
43124344
0 commit comments