Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have an 500 error when my relation table UUID is invalid #2897

Closed
shahryarjb opened this issue May 25, 2018 · 1 comment
Closed

I have an 500 error when my relation table UUID is invalid #2897

shahryarjb opened this issue May 25, 2018 · 1 comment

Comments

@shahryarjb
Copy link

shahryarjb commented May 25, 2018

Environment

  • Elixir version (v1.6.4):
  • Phoenix version (1.3):
  • NodeJS version (v9.3.0):
  • NPM version (5.6.0):
  • Operating system: mac os last update

Expected behavior

it is likely that phoenix Json can't know its relation table which is UUID , For this purpose I have an error, but it know invalid UUID of id table.

please see this post which I have described.
https://elixirforum.com/t/how-to-stop-500-errors-when-uuid-doesnt-match/14072/27

I was forced to write this :

    def changeset(struct, params \\ %{}) do
        struct
        |> cast(params, @all_fields)
        |> validate_required(@all_fields)
        |> validate_field_relational(:cms_learn_category_id)
    end


defp validate_field_relational(changeset, field) do
      field_concerned = get_field(changeset, field)
      case Ecto.UUID.cast(field_concerned) do
        :error ->
            add_error(changeset, field, "relational field is invalid")
        _ ->
          changeset
      end
    end
@chrismccord
Copy link
Member

As this is not a Phoenix issue please refer to your forum post for support requests where folks there can assist you. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants