开发者

How does StumbleUpon store their categories in their Database?

开发者 https://www.devze.com 2023-01-30 14:29 出处:网络
Each user have their own set of chosen categories开发者_JAVA技巧, then only those chosen categories will be shown to the user when they stumble from site to site.

Each user have their own set of chosen categories开发者_JAVA技巧, then only those chosen categories will be shown to the user when they stumble from site to site.

So, my question is this a one to many relationship? Like one user id is connected to many categories in the database?

Then all the categories is stored in one table?


I've never used StumbleUpon, but here is my guess:

They have a User table, a Category table, and a FavoriteCategory table.

The Category table has an id column and a name column. The User table has an id column, an email column, a username column, etc.

The FavoriteCategory table is where the magic happens!

It has a userId column and a categoryId column. Every time a user adds a new favorite category, a new record is added to the FavoriteCategory table with the user's id as the userId and the category's id as the categoryId. All it takes is a simple INNER JOIN to grab all the data in a single query.

With this schema, users can have an unlimited number of favorite categories! :]

Edit: Try reading about third normal form.

0

精彩评论

暂无评论...
验证码 换一张
取 消