mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
docs: Add more info about inline aggregates to Expressions guide
This commit is contained in:
parent
1acf690da9
commit
26c1351f1e
1 changed files with 3 additions and 1 deletions
|
@ -96,13 +96,15 @@ For elixir-backed data layers, they will be a function or an MFA that will be ca
|
||||||
|
|
||||||
## Inline Aggregates
|
## Inline Aggregates
|
||||||
|
|
||||||
Aggregates can be referenced in-line, with their relationship path specified and any options provided that match the options given to `Ash.Query.Aggregate.new/4`. For example:
|
Aggregates such as `count`, `first`, `sum`, etc. can be referenced in-line, with their relationship path specified and any options provided that match the options given to `Ash.Query.Aggregate.new/4`. For example:
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
calculate :grade, :decimal, expr(
|
calculate :grade, :decimal, expr(
|
||||||
count(answers, query: [filter: expr(correct == true)]) /
|
count(answers, query: [filter: expr(correct == true)]) /
|
||||||
count(answers, query: [filter: expr(correct == false)])
|
count(answers, query: [filter: expr(correct == false)])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
calculate :latest_post_published_at, :datetime, expr(max(posts, field: :published_at))
|
||||||
```
|
```
|
||||||
|
|
||||||
The available aggregate kinds can also be seen in the `Ash.Query.Aggregate` module documentation.
|
The available aggregate kinds can also be seen in the `Ash.Query.Aggregate` module documentation.
|
||||||
|
|
Loading…
Reference in a new issue