How to show tag names in a dropdown for many-to-many relationships in AshAdmin?

Hello Ash community, happy to be part of this family!

I’m running into an issue while building a knowledge base. Each entry in my knowledge base should be associated with one or more tags. I’ve set up three tables:

  • tags (stores tag metadata)

  • entries (knowledge base items)

  • entry_tags (join table for many-to-many)

The problem: I’d like to select tags dynamically by name from a dropdown in AshAdmin. But this doesn’t work out of the box, because the Entry resource doesn’t have a direct belongs_to with Tag—it only has a many_to_many through EntryTag. If I add a belongs_to, I’d break 1NF and duplicate the relationship design.

What’s the recommended way in Ash to handle this? Ideally I’d like a clean dropdown (or multi-select) that shows tag names and correctly links them through the join table.

Any suggestions or best practices would be greatly appreciated!

IIRC you can do this by using the label_field configuration on the tag resource, i.e

admin do
  label_field :name
end

I’m not sure actually if this is set up with many_to_many relationships or not :thinking: but couldn’t hurt to try :slight_smile:

I gave this a try and it didn’t work. However, I’ve seen it work in another case where one table had a belongs_to relationship and the other had a has_many relationship with the same table.

Gotcha, yeah we probably need to add that functionality to ash_admin in that case :slight_smile:

Please open an issue

I’ve opened an issue for this now :hot_beverage:

https://github.com/ash-project/ash_admin/issues/362

@oelshark89, maybe you’re interested in having a look at the reproduction to see if it corresponds to your observations?

https://github.com/carlgleisner/ash_admin_dropdown_repro

Unfortunately, I just don’t have time to look into this one :cry: Hopefully some adventurous soul will look at ash_admin and see what can be done to extend this functionality to many_to_many relationships.

Will try to look Into it

Okay, actually I am looking into this. It looks like this is setup only for when you are editing the foreign key directly via organization_id and only for belongs_to relationships currently.

the default create action is not using manage_relationship, and the non default one is. So it’s not anything to do with default or non-default. This just isn’t implemented for manage_relationship arguments.

Same for the original issue, this just isn’t implemented for many_to_many relationships. PRs welcome!