jack_m
Skipping validations when calling `Ash.can?`
Hi there!
I have a resource with a bunch of custom, expensive validations that I want to run on :update and :create actions. Everything works as expected, except that I use Ash.can? on the UI for the sole purpose of enabling/disabling/hiding buttons in a table view (which in a sense is a “:read" view) depending on whether the user can :update each record (and also perform other actions on it).
The problem is that Ash.can? internally creates a changeset and validates it, causing my expensive validations to be run multiple times just for showing the table view in the UI. Is there a way to avoid this? I just need to determine if the user is allowed to :update, I don’t want to validate the resource attributes, which I assume to be valid anyways when loaded from the db, and which in my case have nothing to do with the logic behind the authorization of the action.
I was thinking of manually creating the changeset and passing a custom flag in the context before calling Ash.can?on the changeset, so that I can skip the expensive validations when the flag is set. Is this the idiomatic way to achieve this? Although it seems a bit cumbersome, because it introduces an undocumented “accidental language” (to quote @zachdaniel) in my codebase.
Thanks for your help and insights! ![]()
Jack
First Post!
FlyingNoodle
Ash can has a bunch of options that you can pass:
Maybe :run_queries? or :reuse_values? or :validate? can help you out?







