CakePHP:不确定如何处理半困难的关系
我正在开发我的第一个 CakePHP 应用程序,一个订单/发票系统。订单部分进展顺利,但对于发票我有点需要一些帮助。
我正在使用的数据库结构; 送货单由多个产品组成,而这些产品又包含多个可重复使用的元素(例如多个托盘和产品本身) 。现在,由于一些客户订购的数量较大,他们会获得较低的费率,这是基于时间的(元素 y 从第 1 周到第 9 周为 1 欧元,从第 10 周到第 8 周为相同元素为 1.20 欧元)。当然,有些客户只需要使用每日价格,该价格将以相同的方式存储,只是使用 nulled
customer_id。
现在我的问题是;我完全不知道应该如何处理发票视图,或更具体地说;获取数据的最佳方法是什么,或者我是否应该去练习我的 SQL 编写技能。
I'm working on my first CakePHP app, an order/invoice system. The order-part are coming along nicely, but for the invoices I kinda need some help.
The database structure I'm using; A delivery note consists of multiple products, which in turn exist of multiple re-usable elements (like a number of trays and the product itself). Now because some customer order larger quantities, they get lower rates, which are time-based (from week 1 to 9 €1 for element y, and from week 10 to 8 €1.20 for the same element). Of course some customers just have to use the daily prices, which will be stored the same way, just witha nulled
customer_id.
Now my problem; I have absolutely no idea how I should tackle the invoice view, or more specifically; what the best way is to get the data, or if I should just go and practice my SQL-writing skills.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有发现您的架构有任何重大问题。 Containable 行为应该会让事情变得简单。将其添加到您的发票模型中:
通过为每个元素添加 DefaultPrice 关系,让您的生活更轻松。在您的元素模型中:
现在要构建发票,设置包含参数并将其传递给查找操作。 (我假设您想要显示元素成本的细分,对吧?)
这应该会导致每个元素记录都包含一个 DefaultPrice,并且如果客户收到特殊定价,则还将包含 Price 记录。
注意:您可能需要考虑在“元素”字段中包含 default_price 字段,并避免执行上面的额外连接。每个元素都会有一个默认价格,对吧?
I'm not seeing any major problems with your schema. The Containable behavior should make things easy here. Add it to your Invoice model:
Make your life easier by adding a DefaultPrice relationship for each element. In your Element model:
Now to build your invoice, set up and pass a contain parameter to your find operation. (I assume you want to show a breakdown of element costs, right?)
This should result in each Element record including a DefaultPrice, and if the customer is receiving special pricing, the Price record will also be included.
Note: You may want to consider including a default_price field in the Element field, and avoid having to do the additional join above. Every Element is going to have a default price, right?