How to handle many_to_many relationship in ash_admin

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

Thanks for the quick response and pointing out the update method

change manage_relationship(:users, type: :append_and_remove)

After adding that, the update screen looks like this:

And when I click the Load button, it shows the “search” icon. Clicking that icon adds a row having the “remove” icon.

I have created a git repo which shows this problem

https://github.com/explorer2309/AshManyMany

Thank you for the reproduction :slight_smile: Makes my life a million times easier.

Issue fixed in 0.10.1

1 Like

Great. Its working now.
Many thanks!
:slightly_smiling_face:

1 Like