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
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.
4 Replies
ZachDaniel
ZachDaniel•2y ago
This looks like a bug. Will look into it today.
Jan Ulbrich
Jan UlbrichOP•2y ago
Thank you! 🙂
ZachDaniel
ZachDaniel•2y ago
Could you try ash_json_api main and let me know if that fixes your issue?
Jan Ulbrich
Jan UlbrichOP•2y ago
Hi Daniel, that works nicely now! 🎉 Thank you so much! 👏

Did you find this page helpful?