%{last_login_at: ~U[2023-08-23 19:15:36.122549Z]}, [:last_login_at, :roles]) |> validate_required([:roles])
#Ecto.Changeset<
action: nil,
changes: %{last_login_at: ~U[2023-08-23 19:15:36.122549Z]},
errors: [],
valid?: true
>
А на что он должен ругаться?
я так думал что он должен ругаться на то что в самом ченжсете нет поля
https://hexdocs.pm/ecto/Ecto.Changeset.html#validate_required/3 > If a field is given to validate_required/3 but it has not been passed as parameter during cast/3 (i.e. it has not been changed), then validate_required/3 will check for its current value in the data. If the data contains an non-empty value for the field, then no error is added. This allows developers to use validate_required/3 to perform partial updates. For example, on insert all fields would be required, because their default values on the data are all nil, but on update, if you don't want to change a field that has been previously set, you are not required to pass it as a parameter, since validate_required/3 won't add an error for missing changes as long as the value in the data given to the changeset is not empty.
Обсуждают сегодня