Skip to content

Commit

Permalink
fix: custom message of identities wasn't used
Browse files Browse the repository at this point in the history
  • Loading branch information
lejoko committed Jul 10, 2024
1 parent 2a5d07e commit 36317f5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/data_layer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ defmodule AshMysql.DataLayer do
identity.name == searched_identity_name
end)

%{fields: identity.keys, message: nil}
%{fields: identity.keys, message: identity.message}
end

defp set_table(record, changeset, operation, table_error?) do
Expand Down
2 changes: 1 addition & 1 deletion test/support/resources/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ defmodule AshMysql.Test.Post do
end

identities do
identity(:uniq_one_and_two, [:uniq_one, :uniq_two])
identity(:uniq_one_and_two, [:uniq_one, :uniq_two] , message: "uniq_one_and_two message")
end

attributes do
Expand Down
4 changes: 2 additions & 2 deletions test/unique_identity_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ defmodule AshMysql.Test.UniqueIdentityTest do
end
end

test "unique constraint errors for identities are properly caught" do
test "unique constraint errors for identities are properly caught and custom message is used" do
attrs = %{title: "title", uniq_one: "one", uniq_two: "two"}

Post
|> Ash.Changeset.for_create(:create, attrs)
|> Ash.create!()

assert_raise Ash.Error.Invalid,
~r/Invalid value provided for uniq_one: has already been taken/,
~r/Invalid value provided for uniq_one: uniq_one_and_two message/,
fn ->
Post
|> Ash.Changeset.for_create(:create, attrs)
Expand Down

0 comments on commit 36317f5

Please sign in to comment.