Preload v0.1.1 Preload
To use Preload scopes add a file named <Your.Schema>
where Your.Schema should
be the module of the schema you're trying to preload on.
Next to that add a file with the module <Your.Schema>.Scopes
in this module you can add scope_on_preload/4
functions.
Example
defmodule App.Jobs.Enrollment do
def some_fun(actor, %{preload: preload)) do
Job
|> where(active: true)
|> Preload.scope(preload, actor)
end
end
defmodule App.Jobs.Enrollment.Scopes do
def scope_on_preload(query, preloads, user, options) do
#...
end
end
Link to this section Summary
Functions
The scope accepts queries with preloads as an atom or a list of atoms. It will resolve the main schema of the query and apply the scope_on_preload function on that schema.
Link to this section Functions
Link to this function
scope(query, preloads, user, options \\ %{})
The scope accepts queries with preloads as an atom or a list of atoms. It will resolve the main schema of the query and apply the scope_on_preload function on that schema.
Example
iex> Job
...> |> Preload.scope([:managers, :employees], user, options)
...> |> Repo.get!(id)
%Job{managers: [%User{} | _], employees: [%User{} | _]}