How to build tables in many-to-many relationships?
problem description
has a relationship to manage:
has multiple app, multiple tags per app, tag, multiple user per tag. User may be under tag11 or tag12 of app1, or under tag21 or tag22 of app2.
how to establish a relational table in this case?
additional question:
what is the general solution for the industry to build a tagging system like this (with a large amount of data)?
the environmental background of the problems and what methods you have tried
tried to search for answers, which are basically many-to-many examples of two models. Without such a slightly complicated question, it becomes more and more confusing after thinking about it for a while. You may need to look at different suggestions.
related codes
none
what result do you expect? What is the error message actually seen?
look forward to having a train of thought or guidance.
the many-to-many examples of the two models are your question, but I searched them to say this problem at the data entity bean level, which is not in line with your request.
this can use appid and userid as the joint primary key to query tag
, that is, the table with three main fields of appid, userid,tag
if the tag under the same or different app is different. Then the relationship between app and user can be ignored. Tag stores the many-to-many relationship between appId,user and tag, so create an intermediate table USER_REL_TAG (userId, tagId) to store the relationship between user and tag
An app, may have multiple tag
A tag, may belong to multiple app
a user, may have multiple tag
a tag, may be owned by multiple user
typical many-to-many relationship, app and tag many-to-many, user and tag many-to-many
app and user have no direct connection, no business meaning, so don't think too complicated
three physical tables
app, tag, user
two relational tables
app_tag_rel, fields id (logical primary key of current table), app_id (primary key of app table), tag_id (primary key of tag table)
tag_user_rel, fields id (logical primary key of current table), tag_id (primary key of tag table), user_id (primary key of user table)