Hello everyone ![]()
I’m wondering what the accepted approach is for validating values in the new Scope struct. When I run phx.gen.context , I see that scope is passed into the changeset. Should validations live there, or in the context functions themselves?
In my case, I have added a :permissions field to Scope containing a list of permission atoms (for example, [:create_appointment] ) to control who can create an appointment. Just unsure where to validate that this user has that permission atom so that they can create an appointment. In the context, or in the changeset.
def create_appointment(%Scope{} = scope, attrs) do
with {:ok, appointment = %Appointment{}} <-
%Appointment{}
|> Appointment.changeset(attrs, scope)
|> Repo.insert() do
broadcast(scope, {:created, appointment})
{:ok, appointment}
end
end
Thanks,
Liam : )






















