@@ -3313,12 +3313,12 @@ public function getDocument(string $collection, string $id, array $queries = [],
33133313 $ queries ,
33143314 $ forUpdate
33153315 );
3316-
33173316 if ($ document ->isEmpty ()) {
33183317 return $ document ;
33193318 }
33203319
33213320 $ document ->setAttribute ('$collection ' , $ collection ->getId ());
3321+ $ document ->setAttribute ('main::$collection ' , $ collection ->getId ());
33223322
33233323 if ($ collection ->getId () !== self ::METADATA ) {
33243324 if (!$ validator ->isValid ([
@@ -3354,6 +3354,9 @@ public function getDocument(string $collection, string $id, array $queries = [],
33543354
33553355 $ this ->trigger (self ::EVENT_DOCUMENT_READ , $ document );
33563356
3357+ $ document ->setAttribute ('main::$createdAt ' , DateTime::formatTz ($ document ->getAttribute ('main::$createdAt ' )));
3358+ $ document ->setAttribute ('main::$updatedAt ' , DateTime::formatTz ($ document ->getAttribute ('main::$updatedAt ' )));
3359+
33573360 return $ document ;
33583361 }
33593362
@@ -3692,6 +3695,7 @@ public function createDocument(string $collection, Document $document): Document
36923695 $ document ->setAttribute ('main::$createdAt ' , $ document ->getCreatedAt ());
36933696 $ document ->setAttribute ('main::$updatedAt ' , $ document ->getUpdatedAt ());
36943697 $ document ->setAttribute ('main::$tenant ' , $ document ->getTenant ());
3698+ $ document ->setAttribute ('main::$collection ' , $ document ->getCollection ());
36953699
36963700 return $ document ;
36973701 }
@@ -4015,7 +4019,7 @@ private function relateDocuments(
40154019
40164020 if ($ related ->isEmpty ()) {
40174021 // If the related document doesn't exist, create it, inheriting permissions if none are set
4018- if (!isset ($ relation ['$permissions ' ])) {
4022+ if (!isset ($ relation ['$permissions ' ])) { // todo: Should this be main::$permissions
40194023 $ relation ->setAttribute ('$permissions ' , $ document ->getPermissions ());
40204024 }
40214025
@@ -4228,9 +4232,6 @@ public function updateDocument(string $collection, string $id, Document $documen
42284232
42294233 if (\count ($ old ->getAttribute ($ key )) !== \count ($ value )) {
42304234 $ shouldUpdate = true ;
4231- var_dump ('$shouldUpdate 1 ' );
4232- var_dump ($ shouldUpdate );
4233-
42344235 break ;
42354236 }
42364237
@@ -4244,8 +4245,6 @@ public function updateDocument(string $collection, string $id, Document $documen
42444245 ($ relation instanceof Document && $ relation ->getId () !== $ oldValue )
42454246 ) {
42464247 $ shouldUpdate = true ;
4247- var_dump ('$shouldUpdate 2 ' );
4248- var_dump ($ shouldUpdate );
42494248 break ;
42504249 }
42514250 }
@@ -4329,15 +4328,13 @@ public function updateDocument(string $collection, string $id, Document $documen
43294328
43304329 $ this ->trigger (self ::EVENT_DOCUMENT_UPDATE , $ document );
43314330
4332- /**
4333- * Make this smarter
4334- */
43354331 $ document ->setAttribute ('main::$id ' , $ document ->getId ());
43364332 $ document ->setAttribute ('main::$sequence ' , $ document ->getSequence ());
43374333 $ document ->setAttribute ('main::$permissions ' , $ document ->getPermissions ());
43384334 $ document ->setAttribute ('main::$createdAt ' , $ document ->getCreatedAt ());
43394335 $ document ->setAttribute ('main::$updatedAt ' , $ document ->getUpdatedAt ());
43404336 $ document ->setAttribute ('main::$tenant ' , $ document ->getTenant ());
4337+ $ document ->setAttribute ('main::$collection ' , $ document ->getCollection ());
43414338
43424339 return $ document ;
43434340 }
@@ -4616,7 +4613,7 @@ private function updateDocumentRelationships(Document $collection, Document $old
46164613 $ related = $ this ->skipRelationships (
46174614 fn () => $ this ->getDocument ($ relatedCollection ->getId (), $ value , [Query::select (['$id ' ])])
46184615 );
4619-
4616+ var_dump ( $ related );
46204617 if ($ related ->isEmpty ()) {
46214618 // If no such document exists in related collection
46224619 // For one-one we need to update the related key to null if no relation exists
@@ -4639,6 +4636,13 @@ private function updateDocumentRelationships(Document $collection, Document $old
46394636 $ related ->getId (),
46404637 $ related ->setAttribute ($ twoWayKey , $ document ->getId ())
46414638 ));
4639+ var_dump ($ relatedCollection ->getId ());
4640+ var_dump ($ value );
4641+ var_dump (\gettype ($ value ));
4642+ var_dump ($ twoWay );
4643+ var_dump ($ twoWayKey );
4644+ var_dump ($ related );
4645+ var_dump ($ document ->getId ());
46424646 break ;
46434647 case 'object ' :
46444648 if ($ value instanceof Document) {
@@ -4657,7 +4661,7 @@ private function updateDocumentRelationships(Document $collection, Document $old
46574661
46584662 $ this ->relationshipWriteStack [] = $ relatedCollection ->getId ();
46594663 if ($ related ->isEmpty ()) {
4660- if (!isset ($ value ['$permissions ' ])) {
4664+ if (!isset ($ value ['$permissions ' ])) {// todo check if should be main::$permissions
46614665 $ value ->setAttribute ('$permissions ' , $ document ->getAttribute ('$permissions ' ));
46624666 }
46634667 $ related = $ this ->createDocument (
@@ -4746,7 +4750,7 @@ private function updateDocumentRelationships(Document $collection, Document $old
47464750 );
47474751
47484752 if ($ related ->isEmpty ()) {
4749- if (!isset ($ relation ['$permissions ' ])) {
4753+ if (!isset ($ relation ['$permissions ' ])) { // todo check if should be main::$permissions
47504754 $ relation ->setAttribute ('$permissions ' , $ document ->getAttribute ('$permissions ' ));
47514755 }
47524756 $ this ->createDocument (
@@ -4786,7 +4790,7 @@ private function updateDocumentRelationships(Document $collection, Document $old
47864790 );
47874791
47884792 if ($ related ->isEmpty ()) {
4789- if (!isset ($ value ['$permissions ' ])) {
4793+ if (!isset ($ value ['$permissions ' ])) { // todo check if should be main::$permissions
47904794 $ value ->setAttribute ('$permissions ' , $ document ->getAttribute ('$permissions ' ));
47914795 }
47924796 $ this ->createDocument (
@@ -4859,7 +4863,7 @@ private function updateDocumentRelationships(Document $collection, Document $old
48594863 $ related = $ this ->getDocument ($ relatedCollection ->getId (), $ relation ->getId (), [Query::select (['$id ' ])]);
48604864
48614865 if ($ related ->isEmpty ()) {
4862- if (!isset ($ value ['$permissions ' ])) {
4866+ if (!isset ($ value ['$permissions ' ])) {// todo check if should be main::$permissions
48634867 $ relation ->setAttribute ('$permissions ' , $ document ->getAttribute ('$permissions ' ));
48644868 }
48654869 $ related = $ this ->createDocument (
@@ -6136,6 +6140,9 @@ public function find(string $collection, array $queries = [], string $forPermiss
61366140
61376141 if (!$ node ->isEmpty ()) {
61386142 $ node ->setAttribute ('$collection ' , $ collection ->getId ());
6143+ $ node ->setAttribute ('main::$collection ' , DateTime::formatTz ($ node ->getAttribute ('main::$collection ' )));
6144+ $ node ->setAttribute ('main::$createdAt ' , DateTime::formatTz ($ node ->getAttribute ('main::$createdAt ' )));
6145+ $ node ->setAttribute ('main::$updatedAt ' , DateTime::formatTz ($ node ->getAttribute ('main::$updatedAt ' )));
61396146 }
61406147 }
61416148
@@ -6652,12 +6659,12 @@ private function validateSelections(Document $collection, array $queries): array
66526659
66536660 $ selections = \array_merge ($ selections , $ relationshipSelections );
66546661
6655- $ selections [] = '$id ' ;
6656- $ selections [] = '$sequence ' ;
6657- $ selections [] = '$collection ' ;
6658- $ selections [] = '$createdAt ' ;
6659- $ selections [] = '$updatedAt ' ;
6660- $ selections [] = '$permissions ' ;
6662+ // $selections[] = '$id';
6663+ // $selections[] = '$sequence';
6664+ // $selections[] = '$collection';
6665+ // $selections[] = '$createdAt';
6666+ // $selections[] = '$updatedAt';
6667+ // $selections[] = '$permissions';
66616668
66626669 return \array_values (\array_unique ($ selections ));
66636670 }
0 commit comments