Ash FrameworkAF
Ash Framework8mo ago
8 replies
jeroen11dijk

destroy action based on filters

I currently have a read action and I pass the result to the default destroy action, is it possible to have a destroy action which includes the read part? It seems like destroy only works when passing along the objects

So basically I want to destroy the results of

    read :replannable_routes_by_date do
      prepare build(load: [stops: [orders: [:parcels]]])

      argument :depot_id, :uuid, allow_nil?: false
      filter expr(depot_id == ^arg(:depot_id))

      argument :date, :date, allow_nil?: false
      prepare fn %{arguments: %{date: date}} = query, _ ->
        {start_utc, end_utc} = TimezoneHelpers.date_range_for_timezone(date)

        Ash.Query.filter(
          query,
          expr(projected_departure_time >= ^start_utc and projected_departure_time <= ^end_utc)
        )
      end


      filter expr(replan_locked == false)
    end
Solution
okay so you want to call it via a code interface. you can add the option require_reference?: false to the code interface, and then provide your own filters etc. in the action. (make sure to specify filters or it will delete everything)
Was this page helpful?