设计数据库来保存每个用户最喜欢的帖子 - 需要建议
优惠:优惠 ID、标题、主题...
通缉:wantedID、标题、主题...
会员:会员ID、用户名...
会员可以选择多个主题作为最爱,这些主题将放入 UI 列表中。我该如何为其设计数据库?
我的解决方案:
Favorite:
favoriteID (PK)
memberID - FK
offerID - FK
wantedID - FK
多对多关系。但是,offerID 或 WantID 总是为 NULL,这样可以吗?
Offer: offerID, title, thread ...
Wanted: wantedID, title, thread ...
Member: memberID, username ...
A member can pick many topics as favorite which will be put in a UI list. How can i design the db for it?
My Solution:
Favorite:
favoriteID (PK)
memberID - FK
offerID - FK
wantedID - FK
Many to many relationship. However, there always be NULL either in offerID or wantedID, is this ok?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您说您允许每个用户有多个收藏夹,对吗?
那么为什么不只使用两个表呢?
1) favoriteOffers
最喜欢的OfferID (PK)
会员 ID - FK
OfferID - FK
2) 最喜欢的通缉
最喜欢的通缉 ID (PK)
会员 ID - FK
WantID - FK
您可以获得相同的功能(甚至更多)和清晰的结构。
You say you're allowing multiple favorites per user, right?
Why don't you just use two tables then?
1) favoriteOffers
favoriteOfferID (PK)
memberID - FK
offerID - FK
2) favoriteWanted
favoriteWantedID (PK)
memberID - FK
wantedID - FK
You get the same functionality (maybe even more) with clear clean structure.