improvement: better error messages on incorrect action types

This commit is contained in:
Zach Daniel 2024-09-04 20:41:56 -04:00
parent b999fb10ab
commit d6a973cef0
2 changed files with 14 additions and 2 deletions

View file

@ -1251,6 +1251,19 @@ defmodule Ash.Changeset do
other -> other
end
case action do
%Ash.Resource.Actions.Update{name: name} ->
raise ArgumentError,
message: """
Action #{inspect(changeset.resource)}.#{name} was passed to `Ash.Changeset.for_create`, but it is an update action.
Perhaps you meant to call `Ash.Changeset.for_create` instead?
"""
_ ->
:ok
end
changeset
|> set_context(%{
private: %{

View file

@ -709,8 +709,7 @@ defmodule Ash.Test.Actions.LoadTest do
|> Ash.Query.load([:posts, :latest_post])
|> Ash.read!(authorize?: true)
author =
Ash.load!(author, [:posts, :latest_post], lazy?: true)
Ash.load!(author, [:posts, :latest_post], lazy?: true)
end
test "loading something already loaded still loads it unless lazy?: true" do