Skip to content

changeset:pipe() not return all validation errors. Only return 1 validation error. #3

Description

@okaprinarjaya

Hi @williamthome ,

I have following code

-module(model_user).
-export([changeset/1, changeset/2]).

-define(TYPES, #{
    id => binary,
    username => binary,
    userpassword => binary,
    role => binary,
    created_at => tuple
}).
-define(PERMITTED_ALL_ATTR, maps:keys(?TYPES)).
-define(REQUIRED_ALL_ATTR, maps:keys(?TYPES)).

changeset(Params) ->
    changeset(#{}, Params).

changeset(Data, Params) ->
    Changeset = changeset:cast({Data, ?TYPES}, Params, ?PERMITTED_ALL_ATTR),
    changeset:pipe(Changeset, [
        changeset:validate_required(?REQUIRED_ALL_ATTR),
        changeset:validate_member(role, [<<"ADMIN">>, <<"MITRA">>])
    ]).

Then when I do / execute the validation: model_user:changeset(#{}).
I only get 1 validation error: [{id,{<<"is required">>,#{validation => is_required}}}]
My expectation I get 5 validation error in total.

But I only get the following:

{changeset,[],
           #{id => binary,role => binary,username => binary,
             userpassword => binary,created_at => tuple},
           [id,role,username,userpassword,created_at],
           #{},#{},
           [{id,{<<"is required">>,#{validation => is_required}}}],  %% I only get 1 validation error. How to get all validation errors?
           [undefined,<<>>]}

Thank you 🙏

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions