Model relationships and correlated data¶
A relationship states where a related record is owned and how long it remains available. Choose the construct by the required output shape and lifetime, not by similar-looking syntax.
| Intent | Use | Result |
|---|---|---|
| Separate child rows per parent | nested <generate> |
A child product with explicit per-parent cardinality |
| Embedded objects or lists inside one row | <nestedKey> |
Structured data inside the current product; no separate child product |
| Copy one or several values from one existing source row | <reference> |
One lookup event whose mapped fields remain correlated |
| Reuse an earlier product in a later top-level stage | memstore target and source | Run-local product lineage across separate generation stages |
Parent and child products¶
Nest <generate> when every parent row owns a bounded number of separate child rows. The child count is evaluated per immediate parent, and parent.<field> copies a value from that parent into the child row.
1 2 3 4 5 6 7 8 9 10 | |
This produces two orders rows for each customers row. Use this.parent.<field> when the explicit scope improves readability. At deeper nesting levels, each parent still means only the immediate parent; copy every required key deliberately.
Use <nestedKey> instead when the repeated objects must remain embedded in the same output row rather than becoming a separately addressable product.
Correlated reference values¶
Use one <reference> with <field> children when several output values must come from the same selected source row. Independent references or generators can select different rows and break the correlation.
1 2 3 4 5 6 7 8 9 10 11 | |
The two mapped fields are selected together, preserving the customer ID/country pair. A reference enriches the current row from an existing relational, MongoDB, or weighted project-file source; it does not create a child product by itself. The complete <reference> specification documents single-field mapping, ordered/cyclic selection, uniqueness, weighting, and supported combinations.
Multi-stage product lineage¶
Use a memstore target and source when a later top-level product consumes an earlier product from the same run. The producer's targetEntity and the consumer's memstore:// source id must match. This is a stage boundary, not parent scope: later expressions read the current source row through this.<field>. See the validated memstore model.
Review checklist¶
- The required result is a child product, an embedded value, a lookup, or a later stage—not an accidental mix.
- Parent keys are copied explicitly, and per-parent cardinality is bounded.
- Correlated reference fields share one
<reference>selection. - The source family and selection mode are supported by the referenced element specification.
- Referential integrity and cardinality are asserted in the acceptance checks for the model.
For agent-generated models, the Authoring reference provides validated intent examples and acceptance contracts; the XML above remains the user-facing execution model.