EAV 替代用户定义字段?
鉴于用户必须能够在对象上定义自己的字段,并为这些字段定义允许的值 - 动态(无编译) - 如何在不使用 EAV?
示例:所有对象都需要一个或多个对 123 statusnumber 的引用(允许 1.a 或 2.b 或 3.c)。
Given that users must be able to define their own fields on an object, and define allowed values for these fields - on the fly (no compile) - how would you solve this without using EAV?
Example: All objects need one or more reference to the 123 statusnumber (1.a or 2.b or 3.c allowed).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关系数据库实际上依赖于预定义的稳定模式的存在。
也许您应该查看面向文档的数据库。它们通常允许按文档自由地动态定义属性。
至于模式验证,如果用户可以更改模式本身,则可能需要在您的应用程序中完成。
Relational databases really rely on the presence of a pre-defined and stable schema.
Maybe you should look at document-oriented databases instead. They generally allow free definition of attributes, per document, and on-the-fly.
As for the schema validation, that probably needs to be done in your application if the schema itself can be changed by the user.
如果您必须使用关系数据库,那么有一个(笨拙的)解决方法。我还会推荐 EAV(如果可以的话)或 Thilo 的建议。这是执行此操作的关系方法。
预先警告。以下是这种方法的局限性:
用户可以查看的列数
为每种数据类型创建。
_
每次用户想要一个数字列时,您都会为他分配一个空闲的列main_tbl 中的数字列 (numColumn1 - 5)。在 main_tbl_meanings 中添加一个条目(行),将列 (numcolumn1-5) 映射到用户提供的用户可读名称。
If you must use a relational DB, then there is a (clumsy) workaround. I would also recommed EAV (if you can) or Thilo's suggestion. Here is the relational way of doing it.
Be forewarned. Here are the limitations of this approach:
the number of columns a user can
create for each data type.
_
Each time a user wants a number column you assign him a free number column (numColumn1 - 5) in the main_tbl . Add an entry (row) in the main_tbl_meanings that would map the column (numcolumn1-5) to a user readable name supplied by the user.