Skip to content

Commit

Permalink
Ash framework 3 compatibility (#187)
Browse files Browse the repository at this point in the history
* Ash framework 3 compatibility

Ash version 3 stopped using Ash.ErrorKind

* Check errors for non-nil attributes

When attribute value is not nil, it can still have validation errors
  • Loading branch information
ademenev authored Aug 14, 2024
1 parent b335ff9 commit 3370d62
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/helpers/form_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,17 @@ defmodule PrimerLive.Helpers.FormHelpers do
# Handle other types of changesets: Ash Framework
def _get_ash_framework_field_errors(ash_changeset, field) do
cond do
Map.has_key?(ash_changeset.attributes, field) &&
Map.get(ash_changeset.attributes, field) === nil ->
Map.has_key?(ash_changeset.attributes, field) ->
ash_changeset.errors
|> Enum.filter(fn ash_error -> ash_error.field == field end)
|> Enum.map(fn ash_error ->
code_to_eval =
if Kernel.function_exported?(Ash.Error.Changes.Required, :id, 1),
do: "Ash.ErrorKind.message(e)",
else: "Exception.message(e)"

{message, _binding} =
Code.eval_string("Ash.ErrorKind.message(e)", [e: ash_error],
Code.eval_string(code_to_eval, [e: ash_error],
file: __ENV__.file,
line: __ENV__.line
)
Expand Down

0 comments on commit 3370d62

Please sign in to comment.