DEV Community

Discussion on: Best way to store array type data inside database?

Collapse
 
rhymes profile image
rhymes

So yeah, having a many to many table is one solution. But you can also store them as an array or as JSONB in PostgreSQL. It depends if tags themselves are an entity in your app you want to attach metadata to or are just, well, an array of names you might want to query on (for example to give you the list of posts that have a specific tag)

Thread Thread
 
mittalyashu profile image
Yashu Mittal

Yes, tags itself have a separate entity in the app, to explain it in simpler words, this is how the data output I am expecting.

{
  postId: 3453,
  title: "sdf",
  slug: "sfs",
  tags: [
    {
      name: "sdfs",
      id: "34534"
    },
    {
      name: 'sdfs',
      id: "35344"
    }
  ]
}