Convert many_to_many association to comma delimited string

I have associated tags (id , name)within post. How I can convert this list into comma delimited string with name value?

You are looking for an aggregation. If your DB is PostgreSQL then you will probably be looking at STRING_AGG if I recall the name right. :slight_smile:

So you get something from the database which has the form x and want to convert it into a string which looks like "y"? Did I understood you right?

Since I do not know, how your input looks like exactly, it would be nice if you’d give us an example of your input. Also you haven’t specified how your output shall look like, perhaps you can give some example output that you expect for the given input?

1 Like

I agree you didn’t give us enough to give you a solid answer, but maybe you’re looking for something like:

Enum.map_join(post.tags, ", ", &(&1.name))