在DB中存储标志 [英] Storing flags in a DB
问题描述
在我的申请中,我希望用户选择他的工作日。然后将它们存储在数据库中。当然,我的应用程序将处理用户的数据,如:今天是特定用户的工作日,今天应该工作的用户等等。
In my application, I'd like the user to select his working days. then store them in the database. Of course my application will process the users' data like: Is today a working day for a specific user, who are the users that should work today , ... etc.
我的问题是,这样做最好的做法是什么?我应该使用:
My question is, what is the best practice for doing this? should I use:
- 用户表中的位掩码字段
- 创建多对多关系表表日,用户和days_users。
提前谢谢。
推荐答案
我会说,位掩码字段是一个关系反模式。
I would say that bit mask fields are a relational anti-pattern.
一个字段应该有一个有意义的值,否则最终会出现查询问题 - 每当您需要使用它查询时解析该字段。
A field should have a single meaningful value, otherwise you end up with querying issues - parsing the field every time you need to query using it.
这样一个字段也需要额外的文档,因为它存储的值不是自我描述的。
Such a field also requires extra documentation, as the values it stores are not self describing.
这篇关于在DB中存储标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!