0

I have a similar situation to the user here How to design a database wherein multiple tags(string) are to be associated with an id?

However I'm designing a system where each association (between article and tag) is per user:

User Article Tag
Robin <URL 1> tag1
Robin <URL 1> tag2
Robin <URL 2> tag2
Alex <URL 3> tag3
Jessie <URL 2> tag4

Is this a situation for an EAV table? Or does that only make sense when I get more entities (the users) than values (tags)?

I'm anticipating the all three to be many to many, but likely entity to attribute will be closer to 1 to many, than each attribute to value (closer to true many to many).

0

1 Answer 1

2

In case there is no separate table with a list of tags, and arbitrary strings are allowed, use a standard link table between User and Article and with the tag as a string attribute:

+------------------+-----------------+
| Tag_User_Article |      Type       |
+------------------+-----------------+
| UserId           | Integer (PK,FK) |
| ArticleId        | Integer (PK,FK) |
| Tag              | String (PK)     |
+------------------+-----------------+

For allowing multiple tags for the same combination of user and article, just make the Tag column part of the unique primary key.

In case there is a separate Tag table, just replace the Tag column in the above schema by a forgeign key TagId referencing the Tag table:

+------------------+-----------------+
| Tag_User_Article |      Type       |
+------------------+-----------------+
| UserId           | Integer (PK,FK) |
| ArticleId        | Integer (PK,FK) |
| TagId            | Integer (PK,FK) |
+------------------+-----------------+

And no, EAV is not required here, and it has nothing to do with the number of users or number of tags. EAV would allow you to define or change the kind of attributes for a user or article (or combinations of both) at run time, maybe with different kind of attributes for each user. In this question, however, one knows there is only one kind of attribute (the tag), and it's value is always a string or always a reference to the tag table.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.