In some cases, this is the best option for ordering items.
In particular - when items do not have a natural ordering, or the natural ordering is not something that can easily be done by a program (say natural language - phonemes).
The converse is also true and would be the "meat" of an argument against such fields - if the items do have a natural order that can be easily implemented (numeric, alpha-bet), then such fields do not have a place.
This discussion ignores any requirement of the users to set sorting of items - if such a requirement exists, a "display_order" field is the way to go.
I think it's a tough one, but good that you're aware of it. The only argument I know against is that it blurs the logical distinctions between the roles of your system's components.
However, I find that in a lot of projects, data is returned based on the order of insert (due to auto-incrementing primary keys and scripts that run inserts based on alphabetical / numeric ordering of source data) and sites / other software uses this ordering as an implicit assumption. It's only when you do updates to the data that disrupts the default ordering that people say 'looks like I need display ordering here in the database'
In the majority of implementations where I have used a "Display Order" it has related to navigation / subnavigation in fly-outs. In this case, since the client usually did not have the expertise or need to ever touch the code or database, using display-order along with drag-n-drop proved to be the most efficient design. There are often times when a client will want to display items on a page without a particularly intuitive order to them, or choose to display certain page elements in a interchangable order that they can easliy manipulate and display_order is designed for just this task, so using it makes sense.
In many cases, if you knew the order of the elements, the table might be small enough that the table is a waste to begin with. For example, in our "statuses" table, the statuses ought to be a simple hard-coded array instead of a separate "lookup" table.
As a database guy, I'd have to disagree with this. The odds are good that your statuses are involved in some kind of integrity constraint. When that's the case, putting them in a table makes maintenance (usually adding "just one more" status) a simple matter of inserting a row.
You could also implement that kind of thing as a CHECK constraint, but changing it (adding "just one more" status) would mean altering the table, which in turn usually means a round-trip through QA and testing. Adding a row to a table usually doesn't require QA and regression testing.
But you can't implement statuses that take part in an integrity constraint by hard-coding an array in application code. Application code simply isn't in a position to enforce a constraint (or a view ordering) that's shared among all applications and all users. Only the dbms can do that.
发布评论
评论(4)
在某些情况下,这是订购商品的最佳选择。
特别是 - 当项目没有自然排序,或者自然排序不是程序可以轻松完成的事情(例如自然语言 - 音素)。
反之亦然,并且将成为反对此类字段的“核心” - 如果这些项目确实具有可以轻松实现的自然顺序(数字、字母赌注),那么此类字段就没有位置。
此讨论忽略了用户设置项目排序的任何要求 - 如果存在这样的要求,则可以使用“display_order”字段。
In some cases, this is the best option for ordering items.
In particular - when items do not have a natural ordering, or the natural ordering is not something that can easily be done by a program (say natural language - phonemes).
The converse is also true and would be the "meat" of an argument against such fields - if the items do have a natural order that can be easily implemented (numeric, alpha-bet), then such fields do not have a place.
This discussion ignores any requirement of the users to set sorting of items - if such a requirement exists, a "display_order" field is the way to go.
我认为这是一件艰难的事,但很好的是你意识到了这一点。我所知道的唯一反对的论点是,它模糊了系统组件角色之间的逻辑区别。
但是,我发现在很多项目中,数据是根据插入顺序返回的(由于自动递增主键和基于源数据的字母/数字顺序运行插入的脚本),并且站点/其他软件使用此顺序排序作为隐含的假设。只有当您对数据进行更新时,人们才会说“看起来我需要在数据库中显示顺序”,从而破坏默认顺序
I think it's a tough one, but good that you're aware of it. The only argument I know against is that it blurs the logical distinctions between the roles of your system's components.
However, I find that in a lot of projects, data is returned based on the order of insert (due to auto-incrementing primary keys and scripts that run inserts based on alphabetical / numeric ordering of source data) and sites / other software uses this ordering as an implicit assumption. It's only when you do updates to the data that disrupts the default ordering that people say 'looks like I need display ordering here in the database'
在我使用“显示顺序”的大多数实现中,它与弹出窗口中的导航/子导航相关。在这种情况下,由于客户通常没有专业知识或不需要接触代码或数据库,因此使用显示顺序和拖放操作被证明是最有效的设计。有时,客户希望在页面上显示项目,但没有特别直观的顺序,或者选择以可互换的顺序显示某些页面元素,以便他们可以轻松操作,而 display_order 就是为这项任务而设计的,因此使用这是有道理的。
In the majority of implementations where I have used a "Display Order" it has related to navigation / subnavigation in fly-outs. In this case, since the client usually did not have the expertise or need to ever touch the code or database, using display-order along with drag-n-drop proved to be the most efficient design. There are often times when a client will want to display items on a page without a particularly intuitive order to them, or choose to display certain page elements in a interchangable order that they can easliy manipulate and display_order is designed for just this task, so using it makes sense.
作为一名数据库人员,我不得不不同意这一点。您的身份很可能涉及某种完整性约束。在这种情况下,将它们放入表中可以使维护(通常添加“仅再一个”状态)成为插入一行的简单问题。
您也可以将此类事情实现为 CHECK 约束,但更改它(添加“仅一个”状态)将意味着更改表,这通常意味着通过 QA 和测试进行往返。向表中添加一行通常不需要 QA 和回归测试。
但是您无法通过在应用程序代码中对数组进行硬编码来实现参与完整性约束的状态。应用程序代码根本无法强制执行在所有应用程序和所有用户之间共享的约束(或视图排序)。只有 dbms 可以做到这一点。
As a database guy, I'd have to disagree with this. The odds are good that your statuses are involved in some kind of integrity constraint. When that's the case, putting them in a table makes maintenance (usually adding "just one more" status) a simple matter of inserting a row.
You could also implement that kind of thing as a CHECK constraint, but changing it (adding "just one more" status) would mean altering the table, which in turn usually means a round-trip through QA and testing. Adding a row to a table usually doesn't require QA and regression testing.
But you can't implement statuses that take part in an integrity constraint by hard-coding an array in application code. Application code simply isn't in a position to enforce a constraint (or a view ordering) that's shared among all applications and all users. Only the dbms can do that.