Data Trees

Description

Data trees efficiently load data points (called “fields”) from many related ActiveRecord objects.

Additionally, data trees will:

  • wrap all fields in adapters so that disparate field types respond to the same methods
  • flatten deeply nested fields into a single array, so the caller does not need traverse the tree
  • optionally, adds additional methods to fields using GiraffeQL queries

When to use

  • To read all data related to some domain. The caller just provides a name (usually ‘underwriting’) since the relevant fields are declared in the model.
    • Example: You want to export all underwriting fields to a CSV file
  • To read a number of nested fields by “path” e.g. "project.offtake_type" and "project.market.appraisal", especially if the field types are distinct and the fields span several models
    • Example: you want to load 10 fields to export to a Metabase table

When not to use

  • To read several fields on a single object. In this case, it’s faster to just read the fields directly.

Technology Status at Wunder

Adopt. When loading fields across many objects, Data Trees often lead to simpler and more efficient implementations.

Notes/Resources