Ash FrameworkAF
Ash Framework3w ago
8 replies
matt_savvy

accessing_from for a has_many relationship?

My understanding is that acessing_from should allow me to authorize access to either side of a relationship.
https://hexdocs.pm/ash/Ash.Policy.Check.Builtins.html#accessing_from/2

I have
User
and Profile resources that relate to each other, but only one side is being correctly authorized and I'm not sure why.

User

has_many :profiles, Profile
    policy action(:read) do
      authorize_if accessing_from(Profile, :user)
    end


- Profile
belongs_to :user, User
    policy action(:read) do
      authorize_if accessing_from(User, :user)
    end


When I load the user on one or more Profiles, it works just fine.
When I try to load the profiles on a
User
, it never is authorized.
When I replace this one line in my Profile policies to authorize_if always(), it works just fine, which is why I'm pretty sure it's accessing_from that's the culprit.
Was this page helpful?