views:

211

answers:

1

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.

+1  A: 
Arthur Ronald F D Garcia
Hi Arthur, thanks for this. I think I see where you are going with this, but see my clarification above. How do I handle the need for the id of the inserted return in order to then insert into the applied table?
jlembke
See additional comments. I hope it helps you.regards,
Arthur Ronald F D Garcia
I call this design pattern "repository all over the place"
zvolkov
Hi zvolkov. If you have a big idea, share it with us. First of all, Stackoverflow proposal is share knowledge.
Arthur Ronald F D Garcia
Thanks Arthur, I'll take a close look at this this weekend, but that looks good.
jlembke