ash/test/support/policy_simple/resources/calculations/post_texts.ex
Zach Daniel 49da3638f1 fix: don't reuse requested relationship loads for calculations
this is less efficient, and there are still some cases where
we could combine queries, but we need to first solve the behavioral
issues where relationships loaded for calculations could sometimes be loaded
in an "authorized" state when they should not be. We can improve the
speed/efficiency later, correctness is more important.
2024-07-03 18:32:20 -04:00

23 lines
429 B
Elixir

defmodule Ash.Test.Support.PolicySimple.Calculations.PostTexts do
@moduledoc false
use Ash.Resource.Calculation
@impl true
def init(opts) do
{:ok, opts}
end
@impl true
def load(_query, _opts, _context) do
[posts: [:text]]
end
@impl true
def calculate(records, _opts, %{}) do
Enum.map(records, fn record ->
Enum.map(record.posts, fn post ->
post.text
end)
end)
end
end