DDD - 返回数据库密钥的存储库模式?
这里有一个很大的设计缺陷,但我很难解决它:
业务需求有点复杂,所以我会尽量保持简单。 我们有一张购买表和一张退货表。 当退货时,我们必须找到返回数据库中最旧购买的匹配项,并将其记录在“已应用退货”表中。
因此,当我在该交易中插入退货时,我需要将退货应用于购买记录。
就目前而言,我们有一个调用存储库进行插入的服务。 服务需要知道插入的记录的键是什么,以便它可以通过使用该键插入“已应用”记录来完成事务。
我们基本上陷入困境,因为我的理解是存储库不应返回此类数据。 这是否违背了存储库作为集合的想法?
还有什么选择呢?
澄清:
我们有一个购买表、一个退货表和一个已应用表。
已应用表如下所示 buyId returnId qtyReturned
因此,当插入退货时,我需要购买的 ID(由某些业务规则决定)和新插入的退货的 ID。
There is a big design flaw here, but I'm having trouble solving it:
The business need is a little involved so I'll try to keep this simple.
We have a table with purchases, and a table for returns. When a return is made, we have to find match that return to the oldest purchase in the db, and record that in a "returns applied" table.
So, when I insert a Return, within that transaction, I need to apply the return to a purchase record.
As it stands now, we have a service that calls the repository for the insert. The service needs to know what the key is of that inserted record, so that it can finish the transaction by inserting an "applied" record using that key.
We're basically stuck because my understanding is that a repository should not return this kind of data. Doesn't this defeat the idea of the Repository being a collection?
What is the alternative?
CLARIFICATION:
We have a Purchase table, a Return table, and an Applied table
The applied table looks like this
purchaseId returnId qtyReturned
So when a return is inserted I need the id of a purchase (decided by some business rules) and the id of the newly inserted return.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据你的问题我猜想如下:
I suppose the following according to your question: