zac

zac

I don’t think this is possible, but thought I’d pose the question (I did see this, which is similar but specifically asking if the relationships DSL somehow makes it easier to implement).

Is it possible to create a many to many relationship with an attribute, e.g., along these lines:

relationships do
  many_to_many :members App.Accounts.User do
    through App.Team.Members
    source_attribute_on_join_resource :team_id
    destination_attribute_on_join_resource :user_id

>   attribute :role, :atom do # this bit... can't be done?
>     allow_nil? false
>     constraints [one_of: [:team_member, :team_lead]]
>   end
  end  
end

From what I can see in the relationships DSL adding attributes like this isn’t supported. I can see how that could get difficult.

On the other hand – having very simple support would be awesome, e.g., in this case I just want a :role identifier that must be set. No magic and no tricky other stuff. It could potentially save a good bit of overhead (defining a new property, etc., etc.)

Is this worth writing up as a feature request?

Showing Posts 1 to 4

sevenseacat

sevenseacat

Author of Ash Framework

You’d add that attribute as normal onto your App.Team.Members resource.

zac

zac OP

Ah, right, gotcha.

And then… if I want a policy “only team leads can update the team” I could do something like this?

policy action_type(:update) do
  authorize_if relates_to_actor_via([:members, :user_id])
  authorize_if eval(:members.role == :team_lead)
end
zachdaniel

zachdaniel

Creator of Ash

Every many_to_many has an implicit join relationship, unless you configure its name manually, i.e join_relationship :memberships. It defaults to <relationship>_join_relationship

authorize_if expr(exists(members_join_relationship, role == :team_lead and user_id == ^actor(:id)))
zac

zac OP

Thanks @zachdaniel that definitely helps clarify. :+1:

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews