Skip to main content

spread_into_parent

Function spread_into_parent 

Source
pub fn spread_into_parent(
    parent: &mut Value,
    plan: &EmbedPlan,
    grouped: &HashMap<String, Vec<Value>>,
    columns: &[(String, String)],
)
Expand description

Merge a related resource’s columns into the parent row itself.

This is what the ... of select=title,...directors(name) means. Where attach_to_parent puts the related rows under a key of their own, a spread lifts their columns into the parent object, so the result stays flat.

Spreading a to-many relationship gives each column an array of that column’s value across the matched rows, rather than an array of objects.

columns pairs each requested column with the key it should appear under, which differ when the client aliased it: ...clients(client_name:name) reads name and writes client_name. Listing them explicitly is also what lets a parent with no matching child still carry the right keys with null values, since there is no child row to read the names off.

An empty list spreads nothing, which is what ...clients() means. Falling back to every column the child happens to have would be actively wrong: the related table’s own id would land on top of the parent’s.