Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

validate_required should not updates changes

19 views
Skip to first unread message

Matsa

unread,
Jan 28, 2025, 2:42:50 PMJan 28
to elixir-ecto
Currently `validate_required/2` remove any changes that try to set `nil` to a specific field and add an error "can't be blank".

However the state SHOULD be `nil` and not be considered as not changed but error.

  def changeset(struct_or_changeset, attrs \\ %{})
    struct_or_changeset
    |> cast(attrs, [:my_field])
    |> validate_required([:my_field])
    # There is "no change" here but only an error
    # A workaround is to recast our data
    |> cast(attrs, [:section_content_id])
  end

Any other validation keep the changes and add a new error, but this one change the changeset data and I don't think it should.

Reply all
Reply to author
Forward
0 new messages