Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6554773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:44:23+00:00 2026-05-25T12:44:23+00:00

I am storing tags to posts as a many-to-many relationship, like in this post

  • 0

I am storing tags to posts as a many-to-many relationship, like in this post.

I now want to extend tags to be able to tag entities other than posts. I have all these in tables named posts, links, articles, etc. Should I opt for:

tags_items

tag_id | item_id | item_type
-----------------------------
1        2         post
1        42        link
3        7         article

Or create multiple tables

tags_posts
tag_id | post_id 

tags_links
tag_id | link_id 

tags_article
tag_id | article_id 

This forces me to create a new table for every entity I want to tag, but it makes it easier for me to enforce referential integrity.

What are advantages and disadvantages to each approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:44:23+00:00Added an answer on May 25, 2026 at 12:44 pm

    Of the two choices I would prefer the second. As you say, it makes R.I. much easier. Another option is to super-type your taggable items. They would need to share an ID scheme, but assuming that the IDs are all completely internal (as any good surrogate key should be) that shouldn’t be an issue.

    Taggable_Items
        tag_item_id INT (PK)
    
    Posts
        post_id    INT (PK, FK to tag_item_id in Taggable_Items)
        posted_by  INT (FK to your Users table or whatever)
        post_text  VARCHAR(MAX)
        ...
    
    Links
        link_id      INT (PK, FK to tag_item_id in Taggable_Items)
        url          VARCHAR(1000)
        description  VARCHAR(MAX)
        ...
    
    Tags
        tag_id  INT (PK)
        name    VARCHAR(20)
    
    Tagged_Items
        tag_item_id (PK, FK to tag_item_id in Taggable_Items)
        tag_id      (PK, FK to tag_id in Tags)
    

    I hope that’s clear enough. Please post a comment if it doesn’t make sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have entities Post and Tag , where there is a many-to-many relationship between
I want to generate an url like this: /photo?tags=tag1,tag2,tag3 routes file: GET /photo controllers.Photos.list(tags:Array[String]
In my application I have many-to-many relationship (mapped with FluentNHibernate) between Post and Tag:
I'm trying to implement routing such as the following: posts/535434/This-is-a-post-title posts/tagged/tags+here // Matches {controller}/{action}/{id}
My eventual goal is to generate tag links for blog posts, the tags relating
I simplified a many-to-many relationship case with these mockup tables. Posts: ------------------------------ | id
I have a Post and a Tag model: class Post < ActiveRecord::Base has_and_belongs_to_many :tags
I want to let user add as many tag as he wants to an
I'd like to use relationship from sqlalchemy in my project. I test many-to-many on
I have a page that has many posts by different authors. I want the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.