mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
docs: finish docs on calculations
This commit is contained in:
parent
3b1bde6a39
commit
9d4fc1e2a0
2 changed files with 13 additions and 3 deletions
|
@ -46,14 +46,14 @@ See the documentation for the calculations section in `Ash.Resource.Dsl.calculat
|
|||
The calculations declared on a resource allow for declaring a set of named calculations that can be used by extensions.
|
||||
They can also be loaded in the query using `Ash.Query.load/2`, or after the fact using `c:Ash.Api.load/2`. Calculations declared on the resource will be keys in the resource's struct.
|
||||
|
||||
## Custom aggregates in the query
|
||||
## Custom calculations in the query
|
||||
|
||||
Example:
|
||||
|
||||
```elixir
|
||||
User
|
||||
|> Ash.Query.new()
|
||||
|> Ash.Query.aggregate(:count_of_posts, :count, :posts, filter: [published: true])
|
||||
|> Ash.Query.calculate(:full_name, {Concat, keys: [:first_name, :last_name]}, %{separator: ","})
|
||||
```
|
||||
|
||||
See the documentation for `Ash.Query.aggregate/4` for more information.
|
||||
See the documentation for `Ash.Query.calculate/4` for more information.
|
||||
|
|
|
@ -364,6 +364,16 @@ defmodule Ash.Query do
|
|||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Adds a calculation to the query.
|
||||
|
||||
Calculations are made available on the `calculations` field of the records returned
|
||||
|
||||
The `module_and_opts` argument accepts either a `module` or a `{module, opts}`. For more information
|
||||
on what that module should look like, see `Ash.Calculation`.
|
||||
|
||||
More features for calculations, like passing anonymous functions, will be supported in the future.
|
||||
"""
|
||||
def calculate(query, name, module_and_opts, context \\ %{}) do
|
||||
query = to_query(query)
|
||||
|
||||
|
|
Loading…
Reference in a new issue