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!

1 Like

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

1 Like