mercredi 31 janvier 2018

Designing a Core Data model to remember previous object states

Let's say we have a simple Core Data model which keeps track of transactions a bunch customer makes, but for some reason, when we look at transactions, we want to know the customers address at the time the transaction was made.

If the customer changes their address, what is the best way to store the old state of the customer?

Data model design

One way might be to store the customer's address on the transaction, but that wouldn't work with to-many relationships, e.g. if prices of multiple products in a previous transaction changed, how would we record that?

Another option would be to just duplicate the objects, but then we need some way of knowing which is the current one. Would It be better to create intermediary entities which are related to both the transaction and the customer/product?

Aucun commentaire:

Enregistrer un commentaire