Selecto.AutoRetarget (Selecto v0.4.3)
Automatic retarget detection and application for Selecto queries.
When querying with fields from joined tables only (no source table fields), this module can automatically retarget the query to use the joined table as the source, which can be more efficient.
Auto-retarget is typically used with prevent_denormalization mode in detail views.
Aggregate views handle joins naturally through GROUP BY and don't need retargeting.
Link to this section Summary
Functions
Find the best table to retarget to based on selected columns.
Check if a selecto query should be automatically retargeted based on selected columns.
Determine if a query should be retargeted based on selected columns.
Link to this section Functions
find_retarget_target(selecto, selected_columns)
@spec find_retarget_target(Selecto.Types.t(), [String.t() | atom()]) :: atom() | nil
Find the best table to retarget to based on selected columns.
Returns the table name (as atom) that should become the new source table.
maybe_apply(selecto, opts \\ [])
@spec maybe_apply( Selecto.Types.t(), keyword() ) :: Selecto.Types.t()
Check if a selecto query should be automatically retargeted based on selected columns.
Returns the retargeted selecto if pivot is needed, otherwise returns the original.
options
Options
:view_mode- View type ("detail", "aggregate", "graph"). Only "detail" allows retargeting.
examples
Examples
# Will pivot if only category fields are selected
selecto = Selecto.configure(domain, conn)
retargeted = Selecto.AutoRetarget.maybe_apply(selecto, selected: ["category.name"], view_mode: "detail")
should_retarget?(selecto, selected_columns)
@spec should_retarget?(Selecto.Types.t(), [String.t() | atom()]) :: boolean()
Determine if a query should be retargeted based on selected columns.
Retargeting is beneficial when:
- There are qualified columns from other tables
- NO source table columns are selected (they wouldn't be available after retarget)
- All qualified columns are from tables accessible from a single retarget target