Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/ash.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2970,14 +2970,29 @@ defmodule Ash do
run: (Ash.DataLayer.data_layer_query() ->
{:ok, list(Ash.Resource.Record.t()) | Ash.Page.page() | no_return}
| {:error, Ash.Error.t()}),
load: (list(Ash.Resource.Record.t()) | Ash.Page.page() ->
load: (Ash.Query.t(), list(Ash.Resource.Record.t()) | Ash.Page.page() ->
{:ok, list(Ash.Resource.Record.t()) | Ash.Page.page()}
| {:error, Ash.Error.t()})
}

@doc """
Gets the full query and any runtime calculations that would be loaded

## Pagination

When the query is paginated, `run` returns an `Ash.Page.Offset` or
`Ash.Page.Keyset` rather than a list. The data layer query fetches one row
beyond the page limit so that `more?` can be determined; `run` drops that row
before any `authorize_results` or `after_action` hooks see it, exactly as
`Ash.read/2` does, and sets `more?` (and `count`, when requested) on the page.
For an unpaginated query `run` returns a list of records.

Pass whatever `run` returned to `load`, which loads relationships,
calculations and load-through attributes on the records and returns the same
shape it was given. `load` also accepts the raw rows of a paginated data
layer query you executed yourself, extra row included, and builds the page
from them. Passing `page.results` instead of the page loses `more?`.

## Examples

iex> query = MyApp.Post |> Ash.Query.filter(published: true)
Expand Down
Loading
Loading