创建定价矩阵 - sql 还是常量数组?
我计划为 Rails 中的一个项目创建一个定价矩阵。它应该是一个目的地和出发地点的表格,价格取决于您来的地方和计划去的地方。
我还没有决定如何更好地做到这一点:要么在数据库中为此矩阵制作一个表,要么制作一个大型常量数组。问题是,客户端应该能够编辑这个矩阵,因此它最有可能走数据库路线。
无论如何,什么是一个好的模式呢?目的地id,出发地id,然后价格?目的地和出发 ID 将是包含所有可能位置的表的外键。有更好的方法吗?
I am planning to create a pricing matrix for a project in Rails. It's supposed to be a table of destinations and departure locations, and prices depending on where you came and are planning to go.
I am kinda undecided on how to better do this: either making a table in the db for this matrix, or making a mega array of constants. Problem is, the client should be able to edit this matrix so its most likely going the database route.
Anyhow, what's a good schema for this? Destination id, Departure id, then price? destination and departure ids will be foreign keys for a table containing all possible locations. Is there a better way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使其成为数据库表。
价格唯一不变的就是它们会变化。
补充:
定价(也称为产品保理)是我有很多经验的事情。
您的客户可能还会要求/或欣赏额外的定价工具来帮助他们把事情做好。例如,您的 sw:
您可能还需要担心定价的有效日期。即如何以协调的方式推出一套新的价格。
Make it a db table.
The only thing constant about prices is that they change.
Added:
Pricing (also called product factoring) is something that I have a lot of experience with.
Your clients may also ask/or appreciate added pricing tools to help them get things right. Eg, your sw:
You may also need to worry about effective dates for the pricing. Ie how to roll-out a new set of prices in a co-ordinated way.
我将使用两个表:Location 和 TravelPrice。
这使您可以保留价格历史记录,这对于报告、计费等非常重要。理想情况下,您可以在
TravelPrice
表上触发,确保给定DepartureLocationID 的日期没有间隙或重叠
/DestinationLocationID
组合,并且该对中只有一个EndDate
为 NULL 的记录。I would use two tables, Location and TravelPrice.
This allows you to keep a price history, important for reporting, billing, etc. Ideally you would have trigger on the
TravelPrice
table ensuring that there are no gaps or overlaps in dates for a givenDepartureLocationID
/DestinationLocationID
combination, and that there is only one record with a NULLEndDate
for that pair.我会将其添加到 3 列表中,因为它不一定是矩阵 - 您可能不会从所有地方旅行到所有其他地方。您希望能够编辑它。完成硬编码版本后,系统会要求您对其进行编辑。
此外,随着目的地列表的增长,查询性能和代码维护将成为一个因素。
I would add this to a 3-column table because it's not necessarily a matrix - you might not travel from all places to all other places. You want to be able to edit it. As soon as you are done with your hard-coded version, you'll be asked to edit it.
Also, as the list of destinations grows, query performance and code maintenance will become a factor.