Three customer addresses in one table or in separate tables?

前端 未结 7 2373
慢半拍i
慢半拍i 2021-02-07 17:43

In my application I have a Customer class and an Address class. The Customer class has three instances of the Address class:

7条回答
  •  我寻月下人不归
    2021-02-07 18:03

    Go with 2 tables, Customer, Address.

    Once addresses have been created in the address table do not ordinarily allow them to be modified (perhaps a specific tool to correct typos). IOW make the ID of the address idempotent with the address itself.

    You can now reference these address table entries anywhere. For example when an order is dispatched to a customer the address ID that is referenced a by an Order table can be the same one as in the DeliveryAddressID field in the customer table.

    If the customer wishes to change the currently on file delivery address to a new one, a new address record is created. The historical delivery data is unaffected by this yet new orders automatically use the new address.

    Note this is also helpful when caching Addresss objects (they're immutable and are safe for long term caching), they can be distributed and more easily tested for equality (via the ID property).

提交回复
热议问题