diff --git a/src/database/mod.rs b/src/database/mod.rs index afa6eb8..9dc3cf6 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -500,6 +500,13 @@ impl Database { let is_reverse = p_def.hierarchy.contains(&rel.destination_type) && c_def.hierarchy.contains(&rel.source_type); + // A self-referential edge on a shared ancestor table (entity.parent_id -> entity) matches + // both ways for every type pair. Includes always start from the parent and list what hangs + // under it, so the edge is read in reverse — never from a child up to its parent object. + if is_forward && is_reverse { + is_forward = false; + } + // Structural Cardinality Filtration: // If the schema requires a collection (Array), it is mathematically impossible for a pure // Forward scalar edge (where the parent holds exactly one UUID pointer) to fulfill a One-to-Many request.