Ash FrameworkAF
Ash Frameworkโ€ข2mo agoโ€ข
18 replies
MortenLund

Calculations that depend on other calculations

Hi!

I have an issue with using calculations as mentioned in the "ash-core" channel, but I figured out a bit more!

I have two calculations, both implemented using the Calculation behaviour.

Calculation 1 uses the load callback to fetch a relationship and calculate a list of atoms based on the data from this relationship.
Calculation 2 also loads some relationships, and calculates a map from this. The load callback for calculation 2 does NOT depend on anything from calculation 1

When I run calculation 1 by it-self my resource contains the correct result from Calculation 1, a list of atoms
But if I load calculation 2, in the same Ash.load([:calc1, :calc2]) call the result from calculation 2 is correct, but the value for calculation 1 is now only an empty list.
Adding some IO.inspect I can see that the relationship that calculation 1 depends on is loaded from the DB but its just an empty list inside the calculate function.

  MyResource
  |> Ash.get(id)
  |> Ash.load!([:calc1, :calc2])


But, if I load the calculations using two piped calls to Ash.load! instead both works and the resulting resource is correct with no other changes.

  MyResource
  |> Ash.get(id)
  |> Ash.load!([:calc1])
  |> Ash.load!([:calc2])


Any suggestions, or thoughts on how I could go about to figure out if this is a bug or user-error? ๐Ÿ™‚
Was this page helpful?