How to handle many_to_many relationship in ash_admin – Ash Forum


I am getting started with ash_admin with the following resources:

  • Organisation
  • User
  • UserOrganisation (many to many link table between the User and Organisation)

I can edit the fields of Organisation and User using ash-admin, but I am unable to manage the many to many relationship.

Is there is a guide or example of this somewhere?

Thanks



1 Like

I don’t believe there is a specific example or guide for that with ash_admin. When you say that you are unable to manage the many to many relationship, what happens when you try to do so? Is it just not showing in the UI? Can you show me the action in question?

EDIT: I think the issue is simpler than I realized, after rereading your question. Answer below:

Actions do not accept related data by default. You have to add an argument (the way to accept non-attribute values into an action), and then you have to use that argument. The most straightforward way to do so, and the way that tells ash_admin to generate proper inputs, is with the builtin manage_relationship change. For example:

update :update do
  argument :users, {:array, :map}

  change manage_relationship(:users, type: :append_and_remove)
end



Source link

Leave a Comment