Skip to main content

Module relation_chain

Module relation_chain 

Source
Expand description

Chain relation methods on a Many handle to traverse multi-step associations without declaring a via relation on the schema.

user.todos().category() produces an Association whose path is two steps long (User → todos → category). The query engine lowers this by unfolding into nested IN-subqueries against the outermost relation.

Functions§

chain_dedupes_when_todos_share_category
Many todos sharing a single category yield exactly one category row in the chain result — IN dedupes against the outermost relation.
chain_from_empty_source_is_empty
Empty source: a user with no todos produces an empty chain result.
chain_scopes_per_starting_user
The chain respects the starting source: each user’s chain returns only the categories their own todos belong to, even when the data sets overlap.
chain_skips_null_belongs_to
Deferred<Option<_>> in the chain skips NULL foreign keys. Todos with no category contribute nothing to the chain.
chain_then_filter
Many::filter(expr) after a chain applies a filter to the final relation. The result is the chain’s category set narrowed by the filter.
four_step_chain
A 4-step chain (Org → Team → Project → Issue → Tag) drives the peel_first_step loop through three iterations before reducing to a single-step rewrite. Guards against regressions in the depth-independent part of the unfolder.
has_many_through_has_many
Two HasMany hops in succession (Author → posts → comments). The lowering unfolds into nested IN-subqueries on each BelongsTo pair.
three_step_chain
A 3-step chain (User → Project → Task → Tag) walks the planner’s unfolder more than once. Verifies the recursive nesting and the chain of BelongsTo rewrites at each hop.
user_todos_category
Happy path: HasMany → BelongsTo chain returns the distinct set of categories the user’s todos belong to, with no duplicates even when the user has multiple todos in the same category.