3 ms·
> How does your model take into account orders where order lines do not map to an invoice, or which has invoices which no order lines references? If I understa
by valenterry 5y ago
> How does your model take into account orders where order lines do not map to an invoice, or which has invoices which no order lines references?
If I understand you right, the latter seems easy: the list of orderItems would just be empty.
If there can be orderItems without invoice (why would that happen?) then I'd just add another field "plainOrderItems: List[OrderItem]" next to the bundles.
The rest of the code would not change.
That being said, there can surely be situations where modeling the data is not trivial. It's always exciting to model it in the best way to describe the problem at hand. And with this approach, sometimes you need to model different "views" to make combining things work.
> edit: interesting example btw, I do like a lot of aspects and it was fun seeing some "practical" Scala, haven't had a chance to dig in much. Much appreciated!
You are welcome :)
- magicalhippo 5y ago> If there can be orderItems without invoice (why would that happen?) Because people mess up... In this case they'd then fix the missing invoice references post-consolidation. Stuff like this usually happens either due to stress, lack of experience or training (summer temps are a menace) or just negligence. In addition to our consolidation procedure, I've naturally had to write a procedure to undo the consolidation. > then I'd just add another field "plainOrderItems: List[OrderItem]" next to the bundles. That could work, would be more tedious when you want to operate over all items (we do this fairly often), but not terribly so.
- valenterry 5y agoOkay, interesting. > That could work, would be more tedious when you want to operate over all items (we do this fairly often), but not terribly so. Hm, not really. I've updated the code with a convenience method to see how it feels and I don't think it impacts the ergonomics at all: https://scastie.scala-lang.org/QG1VYuFBQ4qRwfJSjq7bjA https://scastie.scala-lang.org/QG1VYuFBQ4qRwfJSjq7bjA