@@ -3811,9 +3811,13 @@ private function populateOneToManyRelationshipsBatch(array $documents, Document
38113811 // Skip if relationship is already populated (array of Documents)
38123812 $ existingValue = $ document ->getAttribute ($ key );
38133813 if (!empty ($ existingValue ) && is_array ($ existingValue ) && !empty ($ existingValue [0 ]) && $ existingValue [0 ] instanceof Document) {
3814+ error_log ("OneToMany: Skipping already populated relationship ' $ key' for document " . $ document ->getId ());
38143815 continue ;
38153816 }
38163817
3818+ // TEMPORARY: Debug what the existing value looks like when not skipped
3819+ error_log ("OneToMany: Processing ' $ key' for document " . $ document ->getId () . ", existingValue type: " . gettype ($ existingValue ) . ", value: " . json_encode ($ existingValue ));
3820+
38173821 $ parentId = $ document ->getId ();
38183822
38193823 // Check if this parent->children relationship has already been processed
@@ -3822,6 +3826,12 @@ private function populateOneToManyRelationshipsBatch(array $documents, Document
38223826 $ parentIds [] = $ parentId ;
38233827 $ this ->map [$ k ] = true ;
38243828 }
3829+
3830+ // TEMPORARY: Always include to debug map issues
3831+ if (!in_array ($ parentId , $ parentIds )) {
3832+ $ parentIds [] = $ parentId ;
3833+ error_log ("OneToMany: Force-added parentId $ parentId (was blocked by map) " );
3834+ }
38253835 }
38263836
38273837 if (empty ($ parentIds )) {
@@ -3864,7 +3874,9 @@ private function populateOneToManyRelationshipsBatch(array $documents, Document
38643874 // Assign related documents to their parent documents
38653875 foreach ($ documents as $ document ) {
38663876 $ parentId = $ document ->getId ();
3867- $ document ->setAttribute ($ key , $ relatedByParentId [$ parentId ] ?? []);
3877+ $ relatedDocs = $ relatedByParentId [$ parentId ] ?? [];
3878+ error_log ("OneToMany: Assigning " . count ($ relatedDocs ) . " related docs to ' $ key' for document $ parentId " );
3879+ $ document ->setAttribute ($ key , $ relatedDocs );
38683880 }
38693881 }
38703882
@@ -3927,6 +3939,12 @@ private function populateManyToOneRelationshipsBatch(array $documents, Document
39273939 $ childIds [] = $ childId ;
39283940 $ this ->map [$ k ] = true ;
39293941 }
3942+
3943+ // TEMPORARY: Always include to debug map issues
3944+ if (!in_array ($ childId , $ childIds )) {
3945+ $ childIds [] = $ childId ;
3946+ error_log ("ManyToOne: Force-added childId $ childId (was blocked by map) " );
3947+ }
39303948 }
39313949
39323950 if (empty ($ childIds )) {
@@ -4012,6 +4030,12 @@ private function populateManyToManyRelationshipsBatch(array $documents, Document
40124030 $ documentIds [] = $ documentId ;
40134031 $ this ->map [$ k ] = true ;
40144032 }
4033+
4034+ // TEMPORARY: Always include to debug map issues
4035+ if (!in_array ($ documentId , $ documentIds )) {
4036+ $ documentIds [] = $ documentId ;
4037+ error_log ("ManyToMany: Force-added documentId $ documentId (was blocked by map) " );
4038+ }
40154039 }
40164040
40174041 if (empty ($ documentIds )) {
0 commit comments