Ash FrameworkAF
Ash Framework3mo ago
3 replies
Rise

pass attribute to expression in calculation

I have the following expression in a calculation. This works if the resource has the attribute starts_at. But how to make this expression generic that any attribute can be used.

  use Ash.Resource.Calculation

  def expression(_opts, _context) do
    expr(fragment("to_char(?,'DD.MM.YYYY')", starts_at))
  end


Ive tried passing :starts_at in opts but with arguments: %{field: :starts_at}. but how it is not clear how to use it


 calculate :display_starts_at,
              :string,
              {Project.Calculations.FormatDatetime, field: :starts_at}
Was this page helpful?