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