From 2a972d8a79881d470f4099e05bf0766fbeb3a640 Mon Sep 17 00:00:00 2001 From: Satya Date: Wed, 2 Sep 2026 11:41:34 -0400 Subject: [PATCH] Edge resolution: a self-referential base edge is reverse for arrays and for non-pointer scalars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit entity.parent_id -> entity matches every type pair in both directions, and the discovery loop kept forward whenever reverse also matched — so an array include compiled as `parent.parent_id = child.id` and every nested list read back empty. An array can only be the reverse side; a scalar is forward only when the property IS the pointer (`parent` for `parent_id`), otherwise it is the single child that points here (a cover attachment). 1286 library tests pass. Pinned by api's accounting suites on branch activity-task-assignment-lines. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01AvkGU4kQ4wsqxHFpXtZKZM --- src/database/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/database/mod.rs b/src/database/mod.rs index afa6eb8..cec3b44 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -500,6 +500,22 @@ 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. An array can only be the reverse (one-to-many) side; a + // scalar is the forward side only when the property IS the pointer (`parent` for + // `parent_id`) — otherwise it is the single child that points here (a cover attachment). + if is_forward && is_reverse { + let stem = rel + .source_columns + .first() + .map(|c| c.trim_end_matches("_id")) + .unwrap_or(""); + let names_pointer = !stem.is_empty() && prop_name == stem; + if is_array || !names_pointer { + 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.