I am trying to evaluate if i’m going to use Ash and saw this in one of the presentations
Order matters
Ash.load([:some_computed_field, :some_computed_field_2])
Will the following still work?
Ash.load([:some_computed_field_2, :some_computed_field])
Does Ash figure out that :some_computed_field_2 is dependant on :some_computed_field
Think it will be really valuable if Ash can figure this out on its own as it will prevent programming errors. Just doing Ash.load([:some_computed_field, :some_computed_field_2]) feels like its just syntactical improvement
Absolutely!
And if field2 depends on field1, but you don’t actually need the value of field1 - you can write Ash.load(:field2) and it will figure out that it needs to load field1 in order to load field2.
If your field are expressions, eg;
calculate :field2, :integer, expr(field1 + 2)
This dependency management will happen automatically.
If your field is in Elixir code, eg. a calculation in a separate module, then you will need to state the dependencies explicitly and then Ash will manage them for you:
calculate :field2, :integer, DoExpensiveCalculation
defmodule DoExpensiveCalculation do
use Ash.Resource.Calculation
def load(_, _, _), do: [:field2]
def calculate(records) do
# Some Elixir code that can rely on `field2` being loaded on all of the records