Skip to content

Commit

Permalink
Always set the depend columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Monson committed Jul 5, 2023
1 parent 692a71c commit 61e33e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/fob.ex
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,14 @@ defmodule Fob do
selection_mapping = Ordering.selection_mapping(query)

query
|> Ordering.columns()
|> Enum.map(fn {table, name} ->
|> Ordering.dependent_columns()
|> Enum.map(fn {table, name, dependent_columns} ->
key = Map.get(selection_mapping, {table, name}, name)

%PageBreak{
column: name,
value: get_in(record, [Access.key(key)])
value: get_in(record, [Access.key(key)]),
dependent_columns: dependent_columns
}
end)
end
Expand Down
11 changes: 10 additions & 1 deletion lib/fob/ordering.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ defmodule Fob.Ordering do
direction: direction,
column: column,
table: table,
maybe_expression: nil
maybe_expression: nil,
dependent_columns: [column]
}
end

Expand Down Expand Up @@ -78,6 +79,14 @@ defmodule Fob.Ordering do
|> Enum.uniq()
end

@spec dependent_columns(%Query{}) :: [{table(), atom(), any(), list(any())}]
def dependent_columns(%Query{} = query) do
query
|> config()
|> Enum.map(&{&1.table, &1.column, &1.dependent_columns})
|> Enum.uniq()
end

# this mapping can help translate between the columns returned by config/1
# into what will be on the records, so it's useful for fetching values for
# page breaks
Expand Down

0 comments on commit 61e33e2

Please sign in to comment.