Ash FrameworkAF
Ash Framework3y ago
4 replies
Jan Ulbrich

Compile Error with JsonApi using related()

Hi there! 👋 I’m getting error message "(ArgumentError) Found an action of type read while looking for an action of type get_related, Perhaps you passed a changeset with the incorrect action type into your Api?" and I don’t understand how to solve it.

Here’s the code:

relationships do
  has_many :events, Event do
    source_attribute(:extid)
    destination_attribute(:extid)
  end
end

json_api do
  type("alarm")

  includes(events: [])

  routes do
    base("/alarms")

    related(:events, :events_by_extid) do
      route("/:extid/events")
    end
  end
end

actions do
  read :events_by_extid do
    prepare(build(sort: [created_at: :asc]))

    prepare(fn query, context ->
      Ash.Query.after_action(query, fn _query, alarms ->
        {:ok, Event.patch_results_applying_actor_filters(alarms, context)}
      end)
    end)
  end
end


I’m using the
main
branch of ash_json_api together with ash 2.9.4. I went through all Spark DSL stuff, but couldn’t find a clue about get_related searching the documentation.
Was this page helpful?