Skip to content

Commit fbbafc2

Browse files
docs: clarify cascade() trims diagram to subgraph
Update diagram.md and whats-new-22.md to reflect that cascade() returns a trimmed Diagram containing only seed + descendants, while restrict() keeps the full graph intact for chaining. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1bc28f5 commit fbbafc2

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/explanation/whats-new-22.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ The diagram supports two restriction propagation modes with different convergenc
240240

241241
**`restrict()` uses AND at convergence.** A child row is included only if *all* restricted ancestors match. This is the right semantics for data subsetting and export — only rows satisfying every condition are selected. `restrict()` is chainable: call it multiple times to build up conditions from different tables.
242242

243-
Both modes propagate **downstream only** — from the seed table to its descendants. Tables upstream of the seed (its ancestors) are never affected. This matches the semantics of foreign key cascades: deleting a session deletes its trials, not its subject.
243+
Both modes propagate **downstream only** — from the seed table to its descendants. `cascade()` goes further: it trims the returned Diagram to the cascade subgraph, removing all ancestors and unrelated tables. This means `delete()` operates on the entire trimmed diagram with no additional filtering. `restrict()` keeps the full graph intact (to support chaining from multiple seed tables) but only restricts the seed's descendants. This matches the semantics of foreign key cascades: deleting a session deletes its trials, not its subject.
244244

245245
The two modes are mutually exclusive on the same diagram. This prevents accidental mixing of incompatible semantics.
246246

src/reference/specs/diagram.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ Diagrams can propagate restrictions through the dependency graph and execute dat
130130
diag.cascade(table_expr, part_integrity="enforce")
131131
```
132132

133-
Apply a cascade restriction and propagate it downstream through the dependency graph. Only the seed table and its descendants receive restrictionsancestors of the seed table are unaffected by subsequent `delete()` or `preview()` calls. Uses **OR** semantics at convergence — a child row is affected if *any* restricted ancestor reaches it. Designed for delete operations.
133+
Apply a cascade restriction and propagate it downstream through the dependency graph. The returned Diagram is trimmed to the **cascade subgraph**only the seed table and its descendants remain. All ancestors and unrelated tables are removed. Uses **OR** semantics at convergence — a child row is affected if *any* restricted ancestor reaches it. Designed for delete operations.
134134

135135
| Parameter | Type | Default | Description |
136136
|-----------|------|---------|-------------|
137137
| `table_expr` | QueryExpression || A restricted table expression (e.g., `Session & 'subject_id=1'`) |
138138
| `part_integrity` | str | `"enforce"` | Master-part integrity policy |
139139

140-
**Returns:** New `Diagram` with cascade restrictions applied.
140+
**Returns:** New `Diagram` containing only the seed table and its descendants, with cascade restrictions applied.
141141

142142
**Constraints:**
143143

@@ -165,7 +165,7 @@ restricted = diag.cascade(Session & {'subject_id': 'M001'})
165165
diag.restrict(table_expr)
166166
```
167167

168-
Apply a restrict condition and propagate it downstream. Only the seed table and its descendants receive restrictions — ancestors of the seed table are unaffected by subsequent operations. Uses **AND** semantics at convergence — a child row is included only if it satisfies *all* restricted ancestors. Designed for data subsetting and export operations.
168+
Apply a restrict condition and propagate it downstream. Only the seed table and its descendants receive restrictions — ancestors remain in the diagram but are not restricted. Unlike `cascade()`, the diagram is not trimmed (to support chaining from multiple seed tables). Uses **AND** semantics at convergence — a child row is included only if it satisfies *all* restricted ancestors. Designed for data subsetting and export operations.
169169

170170
| Parameter | Type | Default | Description |
171171
|-----------|------|---------|-------------|
@@ -193,7 +193,7 @@ restricted = (diag
193193
diag.delete(transaction=True, prompt=None, dry_run=False)
194194
```
195195

196-
Execute a cascading delete using previously applied cascade restrictions. Tables are deleted in reverse topological order (leaves first) to maintain referential integrity.
196+
Execute a cascading delete on the cascade subgraph. All tables in the diagram are deleted in reverse topological order (leaves first) to maintain referential integrity.
197197

198198
| Parameter | Type | Default | Description |
199199
|-----------|------|---------|-------------|

0 commit comments

Comments
 (0)