I have a schema with a number of fields, :a, :b and :c. I want the user to be able to edit the field :a only but not be able to edit field :b nor :c, how can I achieve that?
this behavior can be controlled by an admin, so he can allow him to edit :b instead of :a
A typical changeset will cast parameters as well as validating them so trying to over-abstract by passing lists of keys isn’t a good path.
Instead, make separate functions:
def basic_changeset(data, attrs) do
data
|> cast(attrs, [:a])
|> validate_required([:a])
end
def admin_changeset(data, attrs) do
data
|> basic_changeset(attrs)
|> cast(attrs, [:b, :c])
|> validate_required([:c])
end