Found read action while expecting an action of type relationship...

Hi, I need to customise a relation get the following error when trying to implement something like relationship(:events, :events_by_extid): ** (ArgumentError) Found an action of type read while looking for an action of type relationship The message itself is pretty obvious, but I can’t find a definition of how a relationship action would look like… 😇
13 Replies
ZachDaniel
ZachDaniel3y ago
🤔 I'm not sure I understand what is relationship/2?
Jan Ulbrich
Jan UlbrichOP3y ago
Oh, sorry: Here’s the bigger picture:
json_api do
type("alarm")

includes(events: [])

routes do
base("/alarms")

index(:read)
get(:read_by_extid)

relationship(:events, :events_by_extid)
end
end
json_api do
type("alarm")

includes(events: [])

routes do
base("/alarms")

index(:read)
get(:read_by_extid)

relationship(:events, :events_by_extid)
end
end
PS: I’m using the main branch of ash_json_api as I needed a current fix from you
ZachDaniel
ZachDaniel3y ago
Hm…that’s definitely a bug There is no relationship action type is there a stacktrace?
Jan Ulbrich
Jan UlbrichOP3y ago
Oh, that explains it Yes, here you go:
** (ArgumentError) Found an action of type read while looking for an action of type relationship

Perhaps you passed a changeset with the incorrect action type into your Api?

(ash 2.6.8) lib/ash/resource/info.ex:534: Ash.Resource.Info.action/3
lib/ticker_web/eventhub/router.ex:2: anonymous fn/5 in :elixir_compiler_0.__MODULE__/1
(elixir 1.13.1) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
lib/ticker_web/eventhub/router.ex:2: anonymous fn/3 in :elixir_compiler_0.__MODULE__/1
(elixir 1.13.1) lib/enum.ex:937: Enum."-each/2-lists^foreach/1-0-"/2
lib/ticker_web/eventhub/router.ex:2: (module)
(elixir 1.13.1) lib/kernel/parallel_compiler.ex:346: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/7
** (ArgumentError) Found an action of type read while looking for an action of type relationship

Perhaps you passed a changeset with the incorrect action type into your Api?

(ash 2.6.8) lib/ash/resource/info.ex:534: Ash.Resource.Info.action/3
lib/ticker_web/eventhub/router.ex:2: anonymous fn/5 in :elixir_compiler_0.__MODULE__/1
(elixir 1.13.1) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
lib/ticker_web/eventhub/router.ex:2: anonymous fn/3 in :elixir_compiler_0.__MODULE__/1
(elixir 1.13.1) lib/enum.ex:937: Enum."-each/2-lists^foreach/1-0-"/2
lib/ticker_web/eventhub/router.ex:2: (module)
(elixir 1.13.1) lib/kernel/parallel_compiler.ex:346: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/7
ZachDaniel
ZachDaniel3y ago
okay, I pushed a surface level fix for that
Jan Ulbrich
Jan UlbrichOP3y ago
Huh, so fast?!
ZachDaniel
ZachDaniel3y ago
you might have more problems 😆
Jan Ulbrich
Jan UlbrichOP3y ago
"Problem" is my middle name! 😄
ZachDaniel
ZachDaniel3y ago
So I don't think you should need events_by_extid Proably just whatever the primary read is on the events resource ah, actually its just the read action to use in this resource, sorry and that read action will have an appropritate filter on it
Jan Ulbrich
Jan UlbrichOP3y ago
Yes, exactly. And I can confirm that it continues, now! 🎉
ZachDaniel
ZachDaniel3y ago
its equivalent to
resource
|> filter_by_id()
|> read_by_action()
|> load(relationship_name)
|> Map.get(relationship_name)
resource
|> filter_by_id()
|> read_by_action()
|> load(relationship_name)
|> Map.get(relationship_name)
Jan Ulbrich
Jan UlbrichOP3y ago
Perfect! As always: Big kudos to you. Ash is amazing! 👏
ZachDaniel
ZachDaniel3y ago
🥳 thanks! Glad we got it working.

Did you find this page helpful?